bethskurrie
2018-03-24 03:39
has joined #pact-jvm

andrewcfitzgerald
2018-03-26 02:45
has joined #pact-jvm

mboudreau
2018-03-26 10:39
has joined #pact-jvm

uglyog
2018-04-03 23:39
has joined #pact-jvm

bethskurrie
2018-05-02 04:58
/github subscribe dius/pact-jvm releases

bethskurrie
2018-05-02 04:58
/github unsubscribe dius/pact-jvm deployments commits public

sgleadow
2018-05-09 07:07
has joined #pact-jvm

abubics
2018-05-09 07:11
has joined #pact-jvm

brentbarker9
2018-05-09 20:56
has joined #pact-jvm

brentbarker9
2018-05-15 23:31
I'm looking at https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider-junit#example-of-http-test specifically the `toStateWithData(Map data)` method. When and what kind of data is that map filled with?

brentbarker9
2018-05-15 23:31
Trying to debug that I get a empty collection


rgshah781988
2018-05-16 07:25
has joined #pact-jvm

james.hogarth
2018-05-16 09:21
has joined #pact-jvm

james.hogarth
2018-05-16 09:21
So I've been following the JVM workshop (https://github.com/DiUS/pact-workshop-jvm) but the provider isn't pushing verification back to the broker. I have my own (unauthenticated) broker which is working fine with the JS workshop and the JVM consumer is pushing to it fine. The provider pact test passes so I know it can contact teh broker, it just doesn't publish the verification. Any ideas what I am missing in the example code? A provider version property not set perhaps? I'm at a loss


brentbarker9
2018-05-16 15:12
is that what you are looking for?

james.hogarth
2018-05-16 15:54
@brentbarker9 I found that which is why I thought about version ... but the JVM workshop implies it should be publishing the verification (like the JS one does) but it clearly isn't working as described

uglyog
2018-05-16 23:39
@james.hogarth are you using the gradle build, or are you using something else?

james.hogarth
2018-05-17 08:05
@uglyog I'm following what the workshop states ... honestly I'm a little confused with that project which part(s) of pact-jvm are being used ... I see gradle, junit and spring behaviour defined in the relevant code. I've opened an issue because it doesn't work like Step13 claims it should and it behaves differently to the JS workshop, with the lack of pact verification publication https://github.com/DiUS/pact-workshop-jvm/issues/9

rgshah781988
2018-05-18 10:16
pact jvm is having multiple option, which is confussing

thomas.heilbronner
2018-05-21 09:24
has joined #pact-jvm

minhdoan
2018-05-21 10:08
has joined #pact-jvm

minhdoan
2018-05-21 10:09
Hi team, i am buidling a Pact record with the response contains: { "Id": 35345786, "DATA_TYPE": { "EntityTypeName": "STRING", } } or { "Id": 35345786, "DATA_TYPE": null I used the pact-jvm-consumer-junit_2.12:3.5.16 and it seems the or() method, e.g: or("DATA_TYPE", null, PM.nullValue(), PM.stringType()) does not work in this case Could you please help to instruct me how to build it? Many thanks!

abhilash.hanumanth
2018-05-21 11:23
has joined #pact-jvm

abhilash.hanumanth
2018-05-21 11:23
@minhdoan

rollertone
2018-05-21 13:35
has joined #pact-jvm

uglyog
2018-05-21 23:06
@minhdoan The OR constructs currently work at the attribute level, because that is what the matchers are applied to.

uglyog
2018-05-21 23:07
It would probably be better for you to have two different test cases, one with the value set and one with a null.

uglyog
2018-05-21 23:13
@abhilash.hanumanth I'm not sure I understand your issue. Do you have an array at the root level?

minhdoan
2018-05-22 02:45
@uglyog Thanks for your suggestion but in my test the mixing is mandatory validation point. So another solution??, e.g: maybe the record with a pair of name/value: "DATA_TYPE": {}/null, the value type is optional and ignored in the created record?

abhilash.hanumanth
2018-05-22 03:17
@uglyog, @minhdoan: Here is my Json array body: ``` [ { "appName": "Analytics", "class": "framework.BootstrapModule", "eventTimestamp": 1524504793160, "host": "localhost", "logLevel": "INFO", "message": "message123", "nodeName": "All-In-One", "source": "logs/analytics-agent.log", "sourceType": "analytics-demo-log", "threadName": "main", "tierName": "AppTier" }, { "appName": "Analytics", "class": "AgentEventServiceClientModule", "eventTimestamp": 1524504794121, "host": "localhost", "logLevel": "INFO", "message": "message456", "nodeName": "All-In-One", "source": "logs/analytics-agent.log", "sourceType": "analytics-demo-log", "threadName": "main", "tierName": "AppTier" } ] ```

abhilash.hanumanth
2018-05-22 03:19
i want to construct pact DSL for the above json body

minhdoan
2018-05-22 03:29
@abhilash.hanumanth the pact builder:

minhdoan
2018-05-22 03:29
.body(new PactDslJsonArray() .object() .stringValue("appName", "Analytics") .stringValue("class", "framework.BootstrapModule") .stringValue("message", "message123") .closeObject() .object() .stringValue("appName", "Analytics") .stringValue("class", "framework.BootstrapModule") .stringValue("message", "message456") .closeObject() ).toPact(); }

minhdoan
2018-05-22 03:29
and the record:

minhdoan
2018-05-22 03:29
"body": [ { "appName": "Analytics", "message": "message123", "class": "framework.BootstrapModule" }, { "appName": "Analytics", "message": "message456", "class": "framework.BootstrapModule" } ]

minhdoan
2018-05-22 03:29
is it fine?


minhdoan
2018-05-22 04:02
but for or(JsonBody, null)

uglyog
2018-05-22 04:21
The problem with using or, is that you are only testing one branch. Wouldn't you want to know your interface works with both an actual value and a missing one? This would require two test cases.

minhdoan
2018-05-22 04:24
@uglyog i think i have just found a workaround by using: .or("DATA_TYPE", null, PM.nullValue(), PM.includesStr("EntityTypeName"), PM.includesStr("STRING"))

minhdoan
2018-05-22 04:25
As i said, because the test uses the type-cast so the actual response may contains both a map (json) or null

minhdoan
2018-05-22 04:26
If we divide to 2 cases, it also fails because if the first only check the null, pactVerify will fail for the value with "DATA_TYPE": { "EntityTypeName": "STRING", } }

minhdoan
2018-05-22 04:26
and vice versa.

minhdoan
2018-05-22 04:27
Could you please help to show me how to divide into 2 test cases and approach to create respective pact records for them?

vinod.baradwaj
2018-05-22 05:54
has joined #pact-jvm

abhilash.hanumanth
2018-05-22 06:45
it worked. Thanks MinhDoan

minhdoan
2018-05-22 06:48
welcome @abhilash.hanumanth

uglyog
2018-05-22 06:58
@minhdoan I would have a pact file with two interactions, one that has the object value and one that has the null value. For the consumer test, this is just having two different tests.

uglyog
2018-05-22 06:59
For verifying the provider, you will need a mechanism (hopefully controlled via provider states) that will return the correct value for the correct interaction in the pact file.

minhdoan
2018-05-22 07:01
yes, i am working on provider test and the actual response is already fixed, could not be controlled via provider states so i think i must stick with the above workaround

scott.osborne1
2018-05-22 18:22
has joined #pact-jvm

minhdoan
2018-05-23 03:06
I have a question with Pact verification logging mechanism. What is the common logging library used? And how i configure it? Thanks!

uglyog
2018-05-23 04:29
It's all based on SLF4J, so you will need to configure an implementation for your project. Logback is good if you are not using something else.

shekharsp27
2018-05-23 05:19
has joined #pact-jvm

avinash.eediga
2018-05-23 05:56
has joined #pact-jvm

minhdoan
2018-05-23 06:53
Thanks @uglyog so much! I will investigate the SLF4J

gopinathlangote11
2018-05-23 13:31
has joined #pact-jvm

paulswilliams
2018-05-23 20:03
has joined #pact-jvm

paulswilliams
2018-05-24 06:20
Hi all.

paulswilliams
2018-05-24 07:13
Hi @abubics

abubics
2018-05-24 07:14
howdy :slightly_smiling_face:

paulswilliams
2018-05-24 07:15
So, I?m currently spiking Consumer Contract Driven Testing for a new project where we need to separate consumer and provider development. I?ve had a good look through the documentation, and kind of understand how I would use Pact to do the consumer testing if they were JUnit style tests.

paulswilliams
2018-05-24 07:16
However, in our project, we?d like to use Cucumber-JVM with a Pact build mock to Acceptance Test the whole client.

paulswilliams
2018-05-24 07:18
I?m just having a play with the DSL as I obviously can?t use the Junit test helpers.

paulswilliams
2018-05-24 07:19
I?ve a couple of issues with the API?s, and wonder if I?m approaching this sensibly, or using ?internal? methods..

paulswilliams
2018-05-24 07:22
The first issue I have is that mock `MockHttpServer.kt::mockServer()` takes in config, but also a pact. Does this mean I can?t instantiate a MockServer that could support multiple Pacts? Ideally, I?d like to setup one or two MockServers, grab the URLs, and then bring up our Spring Boot application injecting these URLS, and run a few ATs against it.

paulswilliams
2018-05-24 07:25
Secondly, the example documentation (https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-consumer-junit) suggests using `runAndWritePact` which takes in the test function, but in our case, again, I?d like to start a mockserver, inject a handle to it?s url, and then drive several selenium -> consumer -> mockServer http chains. Once these asynchronous actions are complete, then I could verify against the mock server. Am I out of luck for these kind of interactions, or just keep looking through the APIs. I?m concerned that I?ll start digging deeper and deeper into the internals that are likely to change?

abubics
2018-05-24 08:12
Basically, the mock server is brought up per test (and shut down after each)

abubics
2018-05-24 08:13
There is a standalone mock server you can run, in a separate process, but that's a completely different testing approach

abubics
2018-05-24 08:15
Pact's sweet spot is unit testing API clients, so the more code you cover, the lower the ratio of its job is being done :)

abubics
2018-05-24 08:18
Pact won't verify behaviour, so you'd probably find that driving stuff through the UI will hit problems with any non-elementary interactions

paulswilliams
2018-05-24 08:51
Understood. The difficulty with our project is that the consuming website is required to have very little logic - that should all be pushed down to the provider. Thus really, all we need to test is that UI interactions will result in the appropriate collaboration with the provider.

paulswilliams
2018-05-24 08:52
The strategy would be to use Pact provider tests to ensure the invocation / shape of results, and exception codes are appropriate. Then detailed testing of the provider would be via other test automation.

paulswilliams
2018-05-24 08:53
It seems a waste to use Pact for the unit testing of our consumers client classes, and then code further fake providers for the Acceptance Tests :confused:

paulswilliams
2018-05-24 09:04
Oh, that sounds like a potentially better fit :confused: Any pointers to documentation for that? It?s kinda what I originally thought Pact would be.

paulswilliams
2018-05-24 09:59
You?re talking about https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-server in that case? Presumably here, we could start the standalone server, run ATs against the real provider, and it would record Pacts. We could then rerun ATs against it in ?stub? mode, but couldn?t verify against it? Just verify that the client still worked against the stub? Then we?d have the Pacts that would allow us to write the provider tests?

paulswilliams
2018-05-24 10:34
So I I can see that pact-jvm-server can be used to record pacts from real interactions between consumer and provider. Can this also be used to run a mocked provider for consumer tests? I can't see this in the documentation? There doesn't appear to be end points for pact uploads, nor a pact folder to allow the server to receive pacts?

vinod.baradwaj
2018-05-24 11:20

vinod.baradwaj
2018-05-24 11:21
i am not able to import `au.com.dius.pact.consumer.exampleclients.ConsumerClient`

vinod.baradwaj
2018-05-24 11:21
i have added pact jvm concumer dependency, ``` <dependency> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-consumer-junit_2.12</artifactId> <version>3.5.16</version> </dependency> ```

vinod.baradwaj
2018-05-24 11:21
what am i missing in this ?

vinod.baradwaj
2018-05-24 11:28
should i have to build my own client ?

gopinathlangote11
2018-05-24 11:28
@vinod.baradwaj Are you(maven) able to download the dependancy?

vinod.baradwaj
2018-05-24 11:28
yeah i am able to download dependency from maven repository

gopinathlangote11
2018-05-24 12:50
@vinod.baradwaj : ``` <dependency> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-consumer-junit_2.12</artifactId> <version>3.5.16</version> </dependency> ``` Here with artifact id `pact-jvm-consumer-junit_2.12` version `3.5.16` is not available. I changed it to `pact-jvm-consumer-junit_2.11` & it was working fine for me.

gopinathlangote11
2018-05-24 12:50
I referred `https://repo1.maven.org/maven2/au/com/dius/` this url to see all artifacts & their versions.


vinod.baradwaj
2018-05-24 12:53
this one has 3.5.16

gopinathlangote11
2018-05-24 12:56
Interesting

paulswilliams
2018-05-24 14:52
Is there a standalone jvm server to support mocking for the consumer tests? Is this where I should use https://github.com/pact-foundation/pact-mock_service ?

abubics
2018-05-24 23:23
What?s your strategy for automating acceptance tests?

abubics
2018-05-24 23:25
I would usually champion screen-driver tests that pass through as few layers as possible (especially not out to network), because more layers = more flaky, especially once you get out of process

abubics
2018-05-24 23:26
Even in Android, my UI tests only test behaviour, and hit API client stubs, in-process, never making it to a network call :slightly_smiling_face:

abubics
2018-05-24 23:28
because acceptance tests usually consist of performing an action, and then verifying that a change happened, I?m not sure how Pact could help . . . but if you have a different approach, I?m excited to hear about it :smile:

abubics
2018-05-24 23:30
This is the base page describing the mock and stub services: https://github.com/pact-foundation/pact-mock_service

abubics
2018-05-24 23:31
but it still might be tricky to use for behaviour

uglyog
2018-05-24 23:54
pact-jvm-server runs the mock server, which uses the pact files to pretend to be the provider.

uglyog
2018-05-24 23:57
That class is in the test code, so is not in the published jar file. Just copy it and use it to create your own. But you should be using your own actual client code.

uglyog
2018-05-25 00:00
You should be able to use any of the standalone mock severs. There are 3 that I know about: https://github.com/pact-foundation/pact-mock_service, https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-server or https://github.com/pact-foundation/pact-stub-server. The later one is different as it does not verify the requests, just returns the matching response.

vinod.baradwaj
2018-05-25 04:57
yeah, understood. I have created my own client..

shirren
2018-05-25 07:19
has joined #pact-jvm

shirren
2018-05-25 07:36
Hi all! I am new to Pact. We have successfully authored some contracts which we successfully validate via pactFile but when we try to use a pact broker via a pactUrl we keep getting a 401 error. Our configuration looks like follows. Any help would be greatly appreciated;

shirren
2018-05-25 07:36
```<serviceProviders> <serviceProvider> <name>xyz</name> <protocol>http</protocol> <host>localhost</host> <port>8080</port> <path>/</path> <pactBroker> <url>https://test.pact.dius.com.au</url> <authentication> <username>${env.PACT_BROKER_USER}</username> <password>${env.PACT_BROKER_PASSWORD}</password> </authentication> </pactBroker> <consumers> <consumer> <name>jsclient</name> <pactUrl>https://test.pact.dius.com.au/pacts/provider/xyz/consumer/abc/latest</pactUrl> </consumer> </consumers> </serviceProvider> </serviceProviders>```

shirren
2018-05-25 07:38
Note that we are using version 3.5.16 of pact-jvm-provider-maven_2.12

shekharsp27
2018-05-25 11:10
Hi Shirren, are you able to login to "https://test.pact.dius.com.au" through browser?

paulswilliams
2018-05-25 13:50
So, I?ve followed advise and am now using Pact to integration test my consumer?s client objects, and provider?s controllers. It doing so, I?m struggling to get a provider verification working: My Spring Boot Tests: ```@RunWith(SpringRestPactRunner.class) @Provider("simple-auth-api") @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @PactFolder("/Users/will/src/simple/web/target/pacts") public class AuthControllerTest { @MockBean AuthService authService; @TestTarget public final Target target = new HttpTarget(8081); @State("test login") public void returnSuccessfulLogin() { when(authService.login("paul", "secret")).thenReturn(new User(123, "paul", "Paul", "Williams")); } }``` with my controller ```@RestController public class AuthController { private final AuthService authService; @Autowired public AuthController(AuthService authService) { this.authService = authService; } @GetMapping(value = "/login", produces = MediaType.APPLICATION_JSON_VALUE) public User login(@RequestParam(value="username", required = false) String username, @RequestParam(value="password", required = false) String password) { return authService.login(username, password); } } ``` should, to my belief pass, but fails with ``` returns a response which has status code 200 (OK) includes headers "Content-Type" with value "application/json;charset=UTF-8" (FAILED) has a matching body (FAILED) Failures: 0) successful login returns a response which has a matching body comparison -> Expected a response type of 'application/json' but the actual type was 'text/plain' 1) successful login returns a response which includes headers "Content-Type" with value "application/json;charset=UTF-8" Expected a header 'Content-Type' but was missing java.lang.AssertionError: 0 - Expected a response type of 'application/json' but the actual type was 'text/plain' 1 - Expected a header 'Content-Type' but was missing```

abubics
2018-05-27 01:06
If you `curl` that endpoint, does it have a `Content-Type` header?

shirren
2018-05-27 09:42
Hi @shekharsp27 yes, I am also able to retrieve the contract via a curl request using basic auth. The maven plugin has no issues publishing, just seem to have trouble retrieving a contract with basic auth. Looking at the plugin code it should work so a bit confused as to why it does not. Have you used maven plugin the way we have?

ashish.dubey91
2018-05-27 19:02
has joined #pact-jvm

ashish.dubey91
2018-05-27 19:03
hi guys. I have a question around testing a contract in a consumer for a particular provider state

ashish.dubey91
2018-05-27 19:04
I mean. I've defined 2 states with the same URL

ashish.dubey91
2018-05-27 19:05
in my consumer tests, I'd like to specify which provider state, before sending request for that URL and verifying the response

paulswilliams
2018-05-27 20:39
@abubics it did from Safari: it was parameter related. I stripped them off, tests went green, and then I re-added them using he dsls rather than manually specifying url?params and tests still pass :+1:

uglyog
2018-05-27 23:54
Use two different tests for this. There is no way to let the mock server know which response to return.

shekharsp27
2018-05-28 05:14
Hi @shirren, I am using maven plugin to verify pacts from pact broker, however in my case the pact broker is running as localhost. I'll try by setting basic auth & will update if that works for me

ashish.dubey91
2018-05-28 05:22
okay. makes sense. I saw it in some example. guess I'll have to use that way. thanks

shirren
2018-05-28 05:44
Cool, thanks for that

abhilash.hanumanth
2018-05-28 14:05
Did anyone implement PACT for kakfa message queue consumer and provider ?

uglyog
2018-05-28 22:50
Yes @abhilash.hanumanth that was how the V3 message pact format came about

abhilash.hanumanth
2018-05-29 05:35
@uglyog: I dont see an example for provider test using pact jvm. Can you please look at my simple kakfa application with simple consumer and producer with a simple message here : https://stackoverflow.com/questions/50569251/pact-jvm-for-message-queues-can-someone-provide-sample-provider-test-for-kafka

abhilash.hanumanth
2018-05-29 10:48
@uglyog: In this blog, this is provider test: ``` class ConfirmationKafkaMessageBuilderTest { @PactVerifyProvider('an order confirmation message') String verifyMessageForOrder() { Order order = new Order() order.setId(10000004) order.setExchange('ASX') order.setSecurityCode('CBA') order.setPrice(BigDecimal.TEN) order.setUnits(15) order.setGst(15.0) order.setFees(BigDecimal.TEN) def message = new ConfirmationKafkaMessageBuilder() .withOrder(order) .build() JsonOutput.toJson(message) } } ``` Can you please tell me what is exactly `ConfirmationKafkaMessageBuilder` ? Is this actual class in kafka producer in source code which publishes message to topic ?

abhilash.hanumanth
2018-05-29 12:57
Here is consumer Test code : ``` package com.appd.contracts; import java.util.HashMap; import java.util.Map; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; import au.com.dius.pact.consumer.MessagePactBuilder; import au.com.dius.pact.consumer.MessagePactProviderRule; import au.com.dius.pact.consumer.Pact; import au.com.dius.pact.consumer.dsl.PactDslJsonBody; import au.com.dius.pact.consumer.PactVerification; import au.com.dius.pact.model.v3.messaging.MessagePact; public class ExampleMessageConsumerTest { @Rule public MessagePactProviderRule mockProvider = new MessagePactProviderRule(this); private byte[] currentMessage; @Pact(provider = "SimpleProvider", consumer = "SimpleConsumer") public MessagePact createPact(MessagePactBuilder builder) { PactDslJsonBody body = new PactDslJsonBody(); body.stringValue("10", "100"); Map<String, String> metadata = new HashMap<>(); metadata.put("contentType", "application/json"); return builder.given("SomeProviderState") .expectsToReceive("a test message") .withMetadata(metadata) .withContent(body) .toPact(); } @Test @PactVerification({"test_provider", "SomeProviderState"}) public void test() throws Exception { Assert.assertNotNull(new String(currentMessage)); } public void setMessage(byte[] messageContents) { currentMessage = messageContents; } } ```

abhilash.hanumanth
2018-05-29 12:57
Can someone tell me how to write provider test for above consumer test ?

gnewitt
2018-05-29 22:48
has joined #pact-jvm

uglyog
2018-05-29 23:25
ConfirmationKafkaMessageBuilder is a class that I wrote that constructs the objects that will become the message. It is nothing special, just implements the builder pattern.

abhilash.hanumanth
2018-05-30 04:18
In ConfirmationKafkaMessageBuilder class, do you actually call the Producer class to construct the message ?

abhilash.hanumanth
2018-05-30 04:20
@uglyog: Lets say this is the sample kafka application which has simple producer and consumer : https://stackoverflow.com/questions/50569251/pact-jvm-for-message-queues-can-someone-provide-sample-provider-test-for-kafka. Can you pls tell me if the below consumer test is correct ? ``` package com.appd.contracts; import java.util.HashMap; import java.util.Map; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; import au.com.dius.pact.consumer.MessagePactBuilder; import au.com.dius.pact.consumer.MessagePactProviderRule; import au.com.dius.pact.consumer.Pact; import au.com.dius.pact.consumer.dsl.PactDslJsonBody; import au.com.dius.pact.consumer.PactVerification; import au.com.dius.pact.model.v3.messaging.MessagePact; public class ExampleMessageConsumerTest { @Rule public MessagePactProviderRule mockProvider = new MessagePactProviderRule(this); private byte[] currentMessage; @Pact(provider = "SimpleProvider", consumer = "SimpleConsumer") public MessagePact createPact(MessagePactBuilder builder) { PactDslJsonBody body = new PactDslJsonBody(); body.stringValue("10", "100"); Map<String, String> metadata = new HashMap<>(); metadata.put("contentType", "application/json"); return builder.given("SomeProviderState") .expectsToReceive("a test message") .withMetadata(metadata) .withContent(body) .toPact(); } @Test @PactVerification({"test_provider", "SomeProviderState"}) public void test() throws Exception { Assert.assertNotNull(new String(currentMessage)); } public void setMessage(byte[] messageContents) { currentMessage = messageContents; } } ```

shekharsp27
2018-05-30 06:30
Hi Abhilash, Yes, on message provider side your test method has to create message and need to publish the message to queue which is configured for testing. PACT will pick up the test method by checking @PactVerifyProvider("This string should match with the string in description string in pact file") and your test method needs to retrieve message which is published and has to return that message. Pact will automatically search for test method which is annotated with @PactVerifyProvider("") and will match the message returned by test method & the message consumer is expecting (which is present in pact file). As in above example (test) function "ConfirmationKafkaMessageBuilder" is must be publishing the message & retrieving message as well

hstene
2018-06-02 13:08
has joined #pact-jvm

ashish.dubey91
2018-06-03 13:35
hey guys, is it possible to write PactDslJsonBody fragments and reuse them in contracts? I'll give an example - I have a product detail API which responds with a product details in a JSON and then there is a list of products endpoint which sends the list of product detail objects. is it possible to define product detail JSON body and reuse it for validating the product list array?

uglyog
2018-06-03 23:46
It should be possible, the only issue is the DSL does not have any way to attach a fragment at some point in the body.

abubics
2018-06-04 00:24
I?m doing some things like that in Kotlin . . . you should be able to do it similarly in Java, just more verbose :stuck_out_tongue:

abubics
2018-06-04 00:25
``` open class PactBase : StringSpec() { val token = "test_token" val builder: PactDslWithProvider = ConsumerPactBuilder .consumer("[REDACTED] Android") .hasPactWith("[REDACTED] BFF") val authToken = "valid_token" val requestHeaders = mapOf("Authorization" to "Bearer $authToken") val responseHeaders = mapOf("Content-Type" to "application/json;charset=utf-8") fun verify(pact: RequestResponsePact, func: [REDACTED]Connector.() -> Unit) { val config = MockProviderConfig.createDefault() val result = runConsumerTest(pact, config, object : PactTestRun { override fun run(mockServer: MockServer) { build[REDACTED]Client(mockServer.getUrl(), { authToken }).func() } }) result shouldBe PactVerificationResult.Ok } } ```

abubics
2018-06-04 00:25
``` class PactTransferTests : PactBase() { init { "makes a transfer and receives a receipt" { val pact = builder .given("a member with some accounts") .uponReceiving("a request to transfer funds between accounts").run { headers(requestHeaders) method("POST") body(LambdaDsl.newJsonBody { with(it) { stringType("toAccountNumber", "S02-01") numberType("amount", BigDecimal("100.00")) } }.build()) path("/member/12345/[REDACTED]") } .willRespondWith().run { status(201) headers(responseHeaders) body(LambdaDsl.newJsonBody { with(it) { stringType("receiptNumber", "receipt-no-123456789") stringType("date", "2018-05-30") stringValue("fromAccount", "abc") stringValue("toAccount", "def") numberValue("amount", 100) } }.build()) } .toPact() verify(pact) { makePaymentTransfer( CreateTransferRequest( sessionToken = token, userId = "12345", from = "abc", to = "def", amount = BigDecimal("100.00") ) ) shouldBe Response.Success( TransferReceipt( number = "receipt-no-123456789", date = "2018-05-30", from = "abc", to = "def", amount = BigDecimal("100.00") ) ) } } } } ```

abubics
2018-06-04 00:26
@ashish.dubey91 The `body()` parameter is an object, so you can create it anywhere and reuse it anywhere else

hstene
2018-06-04 04:56
I am using the `SpringRestPactRunner` but I am not sure how i provide which version of my application which is running the verification. The broker only says version `0.0.0` but I would like it to get the version from the gradle.properties-file in my project. Anyone know how I do that?

hstene
2018-06-04 04:56
``` @Provider(?customer?) @IgnoreNoPactsToVerify @PactBroker(host = ?localhost?, port = ?3000?) @RunWith(SpringRestPactRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class ContractVerificationTest { @Autowired CustomerRepository customerRepository; @TestTarget public final Target target = new SpringBootHttpTarget(); @State({?default?, ?extra?}) public void toDefaultState() { System.out.println(?Now service in default state?); } @State(?Customer with ssn(71039012345) exists.?) public void getCustomerPactTest() { customerRepository.add(Customer.builder().name(?Roger Antonsen?).socialSecurityNumber(?71039012345").build()); } @State(?Customer with socialSecurityNumber(71039012345) exists.?) public void getCustomerPactTest2_0() { customerRepository.add(Customer.builder().name(?Roger Antonsen?).socialSecurityNumber(?71039012345").build()); } } ```

uglyog
2018-06-04 04:58
It uses a Java system property by default: `pact.provider.version`

hstene
2018-06-04 05:00
How do I link the gradle.properties value to that system property :thinking_face: Got any ideas?

uglyog
2018-06-04 05:00
In the test task config

hstene
2018-06-04 05:01
Ah, ofc

uglyog
2018-06-04 05:01
``` test { systemProperty 'pact.provider.version', project.version } ```

uglyog
2018-06-04 05:01
Something like that

hstene
2018-06-04 05:04
``` test { systemProperties['pact.provider.version'] = project.version } ```

hstene
2018-06-04 05:04
Works fine. Thank you :slightly_smiling_face:

vinod.baradwaj
2018-06-04 06:40
when i try to run `mvn pact:verify` i am getting the following error, ``` Unable to parse configuration of mojo au.com.dius:pact-jvm-provider-maven_2.12:3.5.11:verify for parameter pactDirectory: Cannot find 'pactDirectory' in class au.com.dius.pact.provider.maven.Provider ``` these are my build configs, ``` <plugin> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-provider-maven_2.12</artifactId> <version>3.5.11</version> <configuration> <serviceProviders> <!-- You can define as many as you need, but each must have a unique name --> <serviceProvider> <name>flex-master</name> <requestFilter> request.addHeader('Authorization', 'Basic *') </requestFilter> <!-- All the provider properties are optional, and have sensible defaults (shown below) --> <protocol>https</protocol> <host>master.qa1.product.net</host> <pactDirectory>pacts/flex-enterprise</pactDirectory> </serviceProvider> </serviceProviders> </configuration> </plugin> ```

uglyog
2018-06-04 06:42
It needs to be `pactFileDirectory`

vinod.baradwaj
2018-06-04 06:44
thank you... :slightly_smiling_face:

ashish.dubey91
2018-06-04 10:01
thanks @abubics

ashish.dubey91
2018-06-04 10:15
hey. I'm trying to do this check in my contract ``` .minArrayLike("objects", 2) .object() .integerType("type", 21) .closeObject() .closeArray() ```

ashish.dubey91
2018-06-04 10:16
what I'd additionally want is - I can check for existence of another object in the array of this type ``` .object() .integerType("type", 20) .closeObject() ```

ashish.dubey91
2018-06-04 10:17
I can't chain minArrayLike. Ideally I'd want something that checks for inclusion of the example objects in the array

abubics
2018-06-04 23:44
checking the content like that sounds more like a behaviour thing, probably better suited to a unit test

abubics
2018-06-04 23:45
Pact is more for ensuring the shape of the response, not so much the content

mboudreau
2018-06-05 00:23
however, if the value of the content needs to be 20 or 21 because it relates to the shape of the response (like an error code). In that case, I'd probably get a separate interaction specifically for that case.

mboudreau
2018-06-05 00:24
that being said, `integerType("type")` should be more than enough

abubics
2018-06-05 01:06
Yeah, if you?re trying to verify those numbers, you could regex it. But if you?re trying to verify something more sophisticated, maybe don?t do it with Pact :slightly_smiling_face:

abubics
2018-06-05 01:09
@ashish.dubey91 Can you describe the data shape and situation you want to test, rather than just the issues you?re having with the DSL?

ashish.dubey91
2018-06-05 02:07
@abubics I want to test the presence of two types of widgets in the response.

ashish.dubey91
2018-06-05 02:08
the data shape remains the same, but the value of `type` is different

mboudreau
2018-06-05 02:24
@ashish.dubey91 again, the pact test is all about contracts, which is all about structure, not about specifics. You can use the contract to validate that both mock results pass the pact test, then in your unit test, also make sure that 20 and 21 is there as well

mboudreau
2018-06-05 02:25
or you just make 2 different pact interactions for each one

ashish.dubey91
2018-06-05 02:32
technically, the structure of the inner keys can change as well based on the value of type

ashish.dubey91
2018-06-05 02:35
I can make 2 interactions, but I'll essentially be checking the value in both interactions because that value is also part of the contract for certain widget types

mboudreau
2018-06-05 02:37
yeah, think you're going to have to do that then if it changes based on the value

ashish.dubey91
2018-06-05 02:45
which is what I think could have been better if I could chain `minArrayLike` or some other DSL method I could use to achieve this in single interaction

mboudreau
2018-06-05 03:00
yeah, but makes your contract very broad

mboudreau
2018-06-05 03:00
Pact doesn't do this out of the box

ashish.dubey91
2018-06-05 03:20
yeah in a few cases, my contract is indeed a bit broad

vinod.baradwaj
2018-06-06 13:46
i have created this interaction, ```@Pact(provider = "flex-authorisation-service", consumer = "flex-publishindexer-service") public RequestResponsePact createPact(PactDslWithProvider builder) { Map<String, String> headers = new HashMap(); headers.put("Content-Type", "application/vnd.nativ.mio.v1+json"); return builder .given("There is a request to get details of a Job") .uponReceiving("Returns details of the authorisation for the user") .path("/api/filter/5") .query("action=EDIT") .body("{\"objects\":[{\n" + " \"objectId\":1,\n" + " \"accountId\":4,\n" + " \"ownerId\":5,\n" + " \"workspaceId\":1,\n" + " \"typeName\":\"collection\",\n" + " \"privateGroup\":false\n" + "}]}") .method("POST") .willRespondWith() .status(200) .headers(headers) .body("[\n" + " 10908\n" + "]").toPact(); }``` is it possible for me to add matcher for payload body ?


abubics
2018-06-07 00:43
If you have to use Java, it?s quite verbose, but the JSON body DSL exists :slightly_smiling_face:

vinod.baradwaj
2018-06-07 07:42
what if i have a complex body with lot of objects in it ? can i make use of json object mapper and will this DSL make use of it ?

dervis4
2018-06-07 08:26
has joined #pact-jvm

abubics
2018-06-07 10:37
I don't think so (but I don't know much about objectmapper).

abubics
2018-06-07 10:38
If the body has a well-defined structure, and relatively static schema, its complexity shouldn't be a significant issue.

abubics
2018-06-07 10:40
If the content (or schema) is deterministic, based on a known state, you won't have any problems.

vinod.baradwaj
2018-06-08 05:53
thanks @abubics :slightly_smiling_face:

vinod.baradwaj
2018-06-08 07:10
i have request payload something like this, ```{"objects":[{ "objectId":10908, "accountId":10122, "ownerId":10214, "workspaceId":10121, "typeName":"collection", "privateGroup":false }]}```


minhdoan
2018-06-08 08:25
Hi @uglyog and team,

minhdoan
2018-06-08 08:27
I want to create a record to test the request: /odata/CHAIR?$filter=CREATED_BY/FIRST_NAME eq 'LIMS'&$orderby=Id asc

vinod.baradwaj
2018-06-08 08:29
got it.. :+1:

minhdoan
2018-06-08 08:29
With the code as below:

minhdoan
2018-06-08 08:29
.path("/odata/CHAIR") .query("$filter=CREATED_BY/CI_FIRST_NAME eq 'LIMS'&$orderby=Id asc")

minhdoan
2018-06-08 08:31
The record on broker has value:

minhdoan
2018-06-08 08:31
{ "method": "GET", "path": "/odata/CHAIR", "query": "$filter=CREATED_BY%2F_FIRST_NAME+eq+%27LIMS%27&$orderby=Id+asc" }

minhdoan
2018-06-08 08:32
and if i run pactVerify the record, a error code 400 is received

minhdoan
2018-06-08 08:32
{ "error": { "code": "1001", "message": "The types 'Edm.Boolean' and 'Edm.String' are not compatible." } }

minhdoan
2018-06-08 08:32
I think it is a known issue with "+" in the request

minhdoan
2018-06-08 08:33
but i have tried with .path("/odata/CHAIR") .encodedQuery("$filter=CREATED_BY%2FCI_FIRST_NAME%20eq%20%27LIMS%27&$orderby=Id%27asc")

minhdoan
2018-06-08 08:35
and the record is

minhdoan
2018-06-08 08:35
{ "method": "GET", "path": "/odata/CHAIR", "query": "$filter=CREATED_BY%252FIRST_NAME%2520eq%2520%2527LIMS%2527&$orderby=Id%2520asc" }

minhdoan
2018-06-08 08:36
so the pactverify has same error code

minhdoan
2018-06-08 08:36
so any solution on it?

minhdoan
2018-06-08 08:36
Many thanks team!

mr.matt.r.long
2018-06-08 13:45
has joined #pact-jvm

mr.matt.r.long
2018-06-08 14:18
Hi all, I'm having an issue publishing our provider verification, using pact-jvm-provider-spring. The broker details are set in the broker annotation within the test class: `@PactBroker(host = "${pactBrokerHost}", port = "443")` which is successfully pulling the Pact files, but after verification I'm getting the message `Skipping publishing verification results for source ...`. Originally I didn't have the pact.provider.version sys variable set, this is now set by maven surefire plugin

mr.matt.r.long
2018-06-08 14:18
Any help greatly appreciated

mr.matt.r.long
2018-06-08 15:30
Interestingly after downgrading to 3.5.16 the verification was successfully published.

uglyog
2018-06-09 07:41
Thanks for raising the issue. It should not be encoding the space as a +, but as %20

uglyog
2018-06-09 07:43
In that case could you raise an issue? It must be a regression.

daniel.delatorrebabi
2018-06-10 11:22
has joined #pact-jvm

daniel.delatorrebabi
2018-06-10 11:34
Hello guys, I am having some issues when I try to execute gradlew pactVerify from my provider. (editado) My jetty server starts correctly but the process gets stuck when it is executing pact:pact-spring-provider:startProvider (editado) it seems that it never goes to my pactbroker server to verify the pact

daniel.delatorrebabi
2018-06-10 11:46
any idea about this?

daniel.delatorrebabi
2018-06-10 11:48
when I run the tests via junit with intellij the tests are executed correctly and the pact is verified in the pactbroker, but I could not do it with gradle pactVerify

uglyog
2018-06-11 00:53
@daniel.delatorrebabi pactVerify is for verifying a separate running provider. If you are verifying with a JUnit test, it will run as part of the test phase (`gradle test`)

matt
2018-06-11 01:40
has joined #pact-jvm

minhdoan
2018-06-11 02:26
@uglyog The link to the issue here, could you please help to change issue type to bug if it is reasonable? And any plan to fix it? Many thanks!

uglyog
2018-06-11 02:27
sure, I'm looking at some defects today, I'll see if I can sort it out for you

minhdoan
2018-06-11 06:43
:+1::skin-tone-3:

daniel.delatorrebabi
2018-06-11 06:48
Hello uglyog, thanks so much for your response. If I use gradlew test the pact is verified in the pactbroker but the version of my provider is not pushed. Is this behaviour expected?


uglyog
2018-06-11 06:52
Can you provide the version of Pact-JVM you are using?

minhdoan
2018-06-11 06:55
I am using 'au.com.dius:pact-jvm-consumer-junit_2.11:3.5.9' for consumer side test

minhdoan
2018-06-11 06:55
Hope it help

daniel.delatorrebabi
2018-06-11 06:57
thanks so much!

uglyog
2018-06-11 06:57
Just saw your comment on the the issue. Try upgrade to version 3.5.13 or later

daniel.delatorrebabi
2018-06-11 06:57
you helped me a lot!

minhdoan
2018-06-11 06:59
ok, let me try

minhdoan
2018-06-11 07:11
i upgraded to testCompile 'au.com.dius:pact-jvm-consumer-junit_2.11:3.5.17'

minhdoan
2018-06-11 07:11
but the issue still happens

minhdoan
2018-06-11 07:42
And the Broker version is x-pact-broker-version: 2.19.2

minhdoan
2018-06-11 07:42
hope it help

mr.matt.r.long
2018-06-11 09:13
Sure, will log in github today

abhilash.hanumanth
2018-06-11 11:51
can someone point me to example of ```new PactDslJsonBody().and(String name, Object value, MatchingRule... rules)``` ?

abhilash.hanumanth
2018-06-11 11:51
I want to understand how to write MatchingRules


rgshah781988
2018-06-12 04:30
@abhilash.hanumanth

abhilash.hanumanth
2018-06-12 13:49
I have an array of strings of variable length which is expected in response body. For example : ```{ "Conditions":[ "conditionA", "conditionB", "conditionC" ] }``` How do I use stringType() or stringMatcher() for generalizing while creating pact using LambdaDsl with minArrayEachLike() ?

drhansen
2018-06-12 19:27
has joined #pact-jvm

mmonson
2018-06-12 20:02
has joined #pact-jvm


abubics
2018-06-13 02:02
If that doesn?t help, can you be more specific about what you?re having trouble with?

uglyog
2018-06-13 02:02
I think the question is about the java 8 DSL


abubics
2018-06-13 02:02
oh right

abubics
2018-06-13 02:04
I answered a similar query 9 days ago, but I only have Kotlin code samples


abhilash.hanumanth
2018-06-13 02:29
Hi @uglyog: This is creating a 2D array like this : ``` "Conditions": [ [ "foo" ] ] ```

uglyog
2018-06-13 02:30
Have a look at the other tests in that class, there probably is one similar to what you need

abhilash.hanumanth
2018-06-13 03:18
Hi @uglyog : ``` @Test public void testStringArray() { /* [ "Foo", "Bar", "x" ] */ // Old DSL final String pactDslJson = new PactDslJsonArray("", "", null, false) .string("Foo") .stringType("Bar") .stringMatcher("[a-z]", "x") .getBody().toString(); // Lambda DSL final PactDslJsonArray actualPactDsl = new PactDslJsonArray("", "", null, false); final LambdaDslJsonArray array = new LambdaDslJsonArray(actualPactDsl); array .stringValue("Foo") .stringType("Bar") .stringMatcher("[a-z]", "x") .build(); String actualJson = actualPactDsl.getBody().toString(); assertThat(actualJson, is(pactDslJson)); } ``` Above test has the same array example I am looking for but each element is being constructed using LambdaDsl. But in my case, the array which is expected in response is of variable length. So, I am looking to generalize the array construction using LambdaDsl.

abhilash.hanumanth
2018-06-13 03:18
This is my actual array inside an object : ``` { "excludedPackages": [ "name=java,description=Core Java Libraries,system=true", "name=javax,description=Java Extension/J2EE Libraries,system=true", "name=com.sun,description=Sun Reference Implementations/JDK Core Classes,system=true", "name=sun,description=Sun Reference Implementations/JDK Core Classes,system=true", "name=org,description=Common Open Source Libraries like Apache's,system=true", "name=com.bea,description=BEA Core Classes,system=true", "name=com.weblogic,description=Weblogic Server Core Classes,system=true", "name=weblogic,description=Weblogic Server Core Classes,system=true" ] } ```

uglyog
2018-06-13 03:48
Sorry, there is no example for this. But it should not be too hard to work out.

minhdoan
2018-06-13 04:18
I have added comment in the ticket https://github.com/DiUS/pact-jvm/issues/693

minhdoan
2018-06-13 04:18
Please help me on it! Many thanks in advance!

abhilash.hanumanth
2018-06-13 05:59
@uglyog: There is no implementation for such example in eachLike(), minArrayLike(), maxArrayLike() methods

uglyog
2018-06-13 06:02
Hmm, you are correct. There is only support for arrays of objects. Can you raise an issue for this?

abhilash.hanumanth
2018-06-13 06:02
sure

abubics
2018-06-13 07:39
Maybe a misdirection, but having data structures encoded inside strings in JSON is probably a smell :stuck_out_tongue:

abubics
2018-06-13 07:39
if those were broken out to objects, they?d be less brittle, and not incur nested encoding penalties

minhdoan
2018-06-13 07:43
Hi guys, anyone has experience with encoding request URL as the ticket https://github.com/DiUS/pact-jvm/issues/693

minhdoan
2018-06-13 07:43
I am facing stuck and really need your help! Thanks!

minhdoan
2018-06-14 10:18
Hi guys,

minhdoan
2018-06-14 10:19
i want to create a request with an invalid correlationid value in request header

minhdoan
2018-06-14 10:19
the script in @Test method is

minhdoan
2018-06-14 10:19
HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); headers.set(CORRELATION_ID_HEADER_FIELD, INVALID_CORRELATION_ID); HttpEntity request = new HttpEntity<>(null, headers); try { new RestTemplate().exchange(provider.getUrl() + GET_ENTITY, HttpMethod.GET, request, String.class);

minhdoan
2018-06-14 10:20
but i don't know why the pact response creation always fails with error

minhdoan
2018-06-14 10:20
17:16:11.773 [Thread-9] ERROR au.com.dius.pact.consumer.BaseMockServer - Failed to generate response groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object The current character read is 'i' with an int value of 105 Unable to determine the current character, it is not a string, number, array, or object line number 1 index number 0 is not valid for correlationId

thadir
2018-06-17 20:02
has joined #pact-jvm

minhdoan
2018-06-18 03:56
Hi team, anyonehas experience to build Pact record for batch requests?

minhdoan
2018-06-18 03:58
I am doing it but i do not know exactly the type response body should be initialized: PactDslRootValue, PactDslJsonBody, PactDslResponse etc

minhdoan
2018-06-18 04:00
The actual response i received in Postman is:

minhdoan
2018-06-18 04:00
--batch_b8c933bd-2f58-4432-b8dc-ad8280d928b1 Content-Type: application/http Content-Transfer-Encoding: binary HTTP/1.1 200 OK OData-Version: 4.0 Content-Type: application/json;odata.metadata=minimal Content-Length: 328 {"@odata.context":"http://localhost/odata/$metadata#CHAIR/$entity","EntityTypeName":"CHAIR","Id":17368336,} --batch_b8c933bd-2f58-4432-b8dc-ad8280d928b1--

minhdoan
2018-06-18 04:00
the content-type is: multipart/mixed; boundary=batch_b8c933bd-2f58-4432-b8dc-ad8280d928b1

abubics
2018-06-18 04:00
let?s keep it in a thread :slightly_smiling_face:

minhdoan
2018-06-18 04:00
Ok, thanks Boris

abubics
2018-06-18 04:00
it?s a good idea if you can put ``` around the code bits, too

minhdoan
2018-06-18 04:01
:+1:

minhdoan
2018-06-18 04:02
I assume the response body is text so i built the body with ```.body(PactDslRootValue.stringMatcher("--batch_[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}--", "--batch_b8c933bd-2f58-4432-b8dc-ad8280d928b1--"))```

abubics
2018-06-18 04:02
multipart shouldn?t really affect the reconstructed payload

abubics
2018-06-18 04:02
but it affects what is sent over the wire :thinking_face:



abubics
2018-06-18 04:04
if that doesn?t get you far enough, come back and ask again :slightly_smiling_face:

minhdoan
2018-06-18 04:04
Okie, let me try

uglyog
2018-06-18 04:04
Only file uploads are supported at the moment

minhdoan
2018-06-18 04:04
many thanks Boris!


minhdoan
2018-06-18 04:05
@uglyog Do you mean in my example, the body checking has not supported yet, right?

uglyog
2018-06-18 04:06
The DSL only has a `fileUpload` method, which sets up a multipart request.

uglyog
2018-06-18 04:07
You might want to look at that method to see what it is doing

uglyog
2018-06-18 04:08
Actually, the method is `withFileUpload`, and it might work for you as you only have one part

minhdoan
2018-06-18 04:13
Thank you so much! I try it now!

minhdoan
2018-06-18 04:25
Sorry but i am not sure that my case is similar with the File Upload

minhdoan
2018-06-18 04:26
I only want to build response body of a batch request with basic get entity part

minhdoan
2018-06-18 04:26
```Content-Type: multipart/mixed; boundary=batch_b8c933bd-2f58-4432-b8dc-ad8280d928b1```

minhdoan
2018-06-18 04:27
Is withFileUpload utilized in this case as well?

minhdoan
2018-06-18 04:37
My main purpose is build the response body as the line:

minhdoan
2018-06-18 04:37
```willRespondWith(status: 201, body: 'file uploaded ok', headers: ['Content-Type': 'text/plain'])```

minhdoan
2018-06-18 04:38
I received the raw response as:

minhdoan
2018-06-18 04:38
```--batch_b8c933bd-2f58-4432-b8dc-ad8280d928b1 Content-Type: application/http Content-Transfer-Encoding: binary HTTP/1.1 200 OK OData-Version: 4.0 Content-Type: application/json;odata.metadata=minimal Content-Length: 328 {"@odata.context":"http://localhost/odata/$metadata#CHAIR/$entity","EntityTypeName":"CHAIR","Id":17368336,} --batch_b8c933bd-2f58-4432-b8dc-ad8280d928b1--```

minhdoan
2018-06-18 04:38
But it seems not to be string type

uglyog
2018-06-18 04:49
Do you mean that your response body is a multipart body?

minhdoan
2018-06-18 04:57
@uglyog yes, i meant that

uglyog
2018-06-18 04:59
Oh, yeah, multipart bodies are only supported with requests.

uglyog
2018-06-18 05:02
Pact won't understand the batch response content types, so it won't be able to match it


minhdoan
2018-06-18 05:04
Yes, i need this info because i am not sure about the pact implementation

minhdoan
2018-06-18 05:04
Will there plan to support it? And i will add the info to the ticket?

uglyog
2018-06-18 05:05
If you add the information to the ticket, then it won't get lost, because I doubt anyone will refer back to slack

uglyog
2018-06-18 05:05
That way when that ticket is worked on, we will know to also support batch responses

minhdoan
2018-06-18 05:10
(y)

minhdoan
2018-06-18 05:10
I am adding, many thanks for your guide!

vinod.baradwaj
2018-06-18 13:19
i am not able to create separate interactions for endpoint with different id's. for eg i have an endpoints like this `/api/collections/10900` and `/api/collections/10908` i cant use matchers/regex because i need to provide different response for both the requests. Is there someway i can have multiple interactions added in same pact file for different id's in the endpoint ?

rgshah781988
2018-06-18 13:38
Is it POST call then possible via different body.

rgshah781988
2018-06-18 13:39
If it is GET call then sorry.

vinod.baradwaj
2018-06-18 13:39
i need for get

vinod.baradwaj
2018-06-18 13:39
:disappointed:

drhansen
2018-06-18 18:26
I am setting up pact as a provider in Java. I am seeing quite a few examples around the web of how to do it but they all differ quite a bit. Does someone have a guide or clear example that they prefer (set up and to run a test)? We have a spring boot application and are using gradle.

tlane
2018-06-18 18:42
has joined #pact-jvm

uglyog
2018-06-18 23:14
Are you looking to write a consumer test, or verify the provider?

kra
2018-06-19 20:39
has joined #pact-jvm

kra
2018-06-19 20:40
Hi @here:slightly_smiling_face: I am pretty new to pact and currently troubleshooting my provider test (Spring Boot, Junit5): When I start my test I get: request Failed - Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect What am I missing? ` @SpringBootTest @Provider("GoalProvider") @PactFolder("pacts") @ExtendWith({ SpringExtension.class }) class GoalProviderPactTest { @Autowired GoalRepository goalRepository; @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); } @State("default") public void toDefaultState() { // Prepare service before interaction that require "default" state goalRepository.saveAndFlush(goal); } } `

kra
2018-06-19 20:53
Am I right that I should start my service with (SpringExtension) instead of mocking it with wiremock (like in most samples)?

uglyog
2018-06-19 23:22
The problem with examples is they are just test examples and there is no real service to start

minhdoan
2018-06-20 03:26
@abubics @uglyog Morning and nice day!

minhdoan
2018-06-20 03:27
I have raised an ticket for Batch request supporting. Please help to take a look and provide your ideas! https://github.com/DiUS/pact-jvm/issues/709

minhdoan
2018-06-20 03:27
Many thanks!

kra
2018-06-20 05:41
ok so my assumption to start my whole service is correct?

kra
2018-06-20 05:53
any idea what I am doing wrong that I get the conncetion refused error?

uglyog
2018-06-20 05:55
Not starting the service, or it's running on a different port?

kra
2018-06-20 05:58
let me check

kra
2018-06-20 05:59
could i set the port to which the pact requests are sent?

uglyog
2018-06-20 06:05
Yes, you should be able to inject the port, and then set the port when you define the target

kra
2018-06-20 06:15
my tomcat ist starting on 8099

kra
2018-06-20 06:15
however, The error message still says 8080

kra
2018-06-20 06:15
i do this: HttpTestTarget target = new HttpTestTarget("localhost",8099); context.setTarget(target); context.verifyInteraction();

kra
2018-06-20 06:33
the target seems to have no impact

kra
2018-06-20 06:33
when i set the port to 8080, it workds

kra
2018-06-20 12:53
Hi. Is there any sample of how to upload pact files/communication in general to a pact-broker in a java unit test?

kra
2018-06-20 12:53
I know that there is a @PactBroker annotation but have no other references

uglyog
2018-06-21 00:27
You can use either the Maven or Gradle plugin to publish the pacts files

shekharsp27
2018-06-21 12:53
Does the pact verify process has the ability to wait until provider application gets up & running. In case of using webhook feature from pact-broker

uglyog
2018-06-21 23:20
No, but it does support you providing a start provider step in which you could do the wait (in Gradle). In Maven, you could setup a pre-verification step using the standard Maven phases.

shekharsp27
2018-06-22 06:44
Thanks

santoshtrip
2018-06-26 01:19
has joined #pact-jvm

can
2018-07-02 12:04
has joined #pact-jvm

minhdoan
2018-07-04 06:55
Does anyone has experience with requests with space(s) in resource path or query options?

minhdoan
2018-07-04 06:55
Could you please help me on it?

mboudreau
2018-07-04 07:03
all spaces should be html encoded to `%20`

uglyog
2018-07-05 02:21
@paisrikanth can you provide the Gradle version, Pact version and any logs

paisrikanth
2018-07-05 02:21
has joined #pact-jvm

paisrikanth
2018-07-05 02:25
gradle version is 3.3

uglyog
2018-07-05 02:25
Also the java version

paisrikanth
2018-07-05 02:26
java is 1.8

paisrikanth
2018-07-05 02:26
logs

paisrikanth
2018-07-05 02:30
pact version - au.com.dius:pact-jvm-provider-gradle_2.11:3.5.0

uglyog
2018-07-05 02:31
Are there any java hprof files (in the form like `java_pid12345.hprof`) in your current working directory?

paisrikanth
2018-07-05 02:32
no

uglyog
2018-07-05 02:34
and what does running `./gradlew --status` give?

uglyog
2018-07-05 02:37
Your Gradle daemons are definitely not happy. Can you try with a later version of Pact-JVM. Latest is `au.com.dius:pact-jvm-provider-gradle_2.12:3.5.19`

paisrikanth
2018-07-05 02:38
I have this in my build.gradle file and running the command ./gradlew pactPublish

paisrikanth
2018-07-05 02:38
updating the version

paisrikanth
2018-07-05 02:49
gradle is still syncing :disappointed:

paisrikanth
2018-07-05 02:51
i still get the same error

uglyog
2018-07-05 02:52
hmm, ok, are you able to try with a different version of Gradle? 4.8.1 is the latest.

paisrikanth
2018-07-05 02:53
let me try that

paisrikanth
2018-07-05 02:55
is the build.gradle snippet i posted earlier correct >?

uglyog
2018-07-05 02:56
yes, that is ok

uglyog
2018-07-05 02:57
apart from `pactBrokerUrl = 'my-url'`, but I assume that will be your proper URL

paisrikanth
2018-07-05 02:57
yes

paisrikanth
2018-07-05 03:02
does the gradle 4.8.1 work with android studio 2.3.3

uglyog
2018-07-05 03:05
It should be ok, but you'll have to give it a try

paisrikanth
2018-07-05 03:11
trying it

paisrikanth
2018-07-05 03:18
@uglyog - I'm trying this on the local machine, should this be a problem ?

paisrikanth
2018-07-05 03:18
I just want to make sure the local pacts are uploading before I integrate this with Jenkins

uglyog
2018-07-05 03:21
Should not be a problem, but I have no idea why your Gradle agents are hanging

paisrikanth
2018-07-05 04:22
no luck with the gradle

paisrikanth
2018-07-05 04:22
4.8.1

paisrikanth
2018-07-05 04:22
:disappointed:

paisrikanth
2018-07-05 04:23
very strange not sure y the gradle crashes

uglyog
2018-07-05 04:23
Bummer

uglyog
2018-07-05 04:24
Ok, try running with `-d` to enable debug logging, but you will get a *lot* of output

uglyog
2018-07-05 04:25
You can also try without the daemon (`--no-daemon `)

ssn899
2018-07-05 05:02
has joined #pact-jvm

paisrikanth
2018-07-06 01:24
@uglyog I got it working

uglyog
2018-07-06 01:25
Yay! What was the issue?

paisrikanth
2018-07-06 01:25
code in the gradle file was required if version 2.1 and above the classpath dependency was killing it

uglyog
2018-07-06 01:26
oh, wow! That's good to know. I'll update the docs about that

paisrikanth
2018-07-06 01:26
also it works only with 3.2.11

paisrikanth
2018-07-06 01:26
the latest version crashes

uglyog
2018-07-06 01:27
Is that Gradle or pact-jvm version?

paisrikanth
2018-07-06 01:27
pact-jvm version

uglyog
2018-07-06 01:27
Can you provide your previous snippet with the build classpath?

paisrikanth
2018-07-06 01:28
this one worked for me where as the latest version is 3.5.19 which crashes

uglyog
2018-07-06 01:29
With Gradle 3.3?

paisrikanth
2018-07-06 01:29
yes

paisrikanth
2018-07-06 01:29
i haven't tested with latest gradle for pact-jvm version 3.5.19

uglyog
2018-07-06 01:30
Can you raise an issue for this at https://github.com/DiUS/pact-jvm

paisrikanth
2018-07-06 01:30
sure


paisrikanth
2018-07-06 01:31
the maven cannot find this

minhdoan
2018-07-06 12:02
Hi Michel! This is my issue i faced with the spaces in URL


minhdoan
2018-07-06 12:03
I have tried to downgraded the gradle to 4.7 and pactJvmVersion to "3.5.18", both consumer side and provider side.

minhdoan
2018-07-06 12:04
But the issue with + in url sent to provider still exists.

minhdoan
2018-07-06 12:05
@mboudreau Could you please help me on it? It blocks me some weeks :disappointed:. I think it is a basic feature so maybe my configuration is not correct or something like that.

minhdoan
2018-07-06 12:07
Have you tried with a record with spaces in URL? Could you please share me the basic script to resolve the issue?

minhdoan
2018-07-06 12:07
Many thanksssss again!

yamad
2018-07-07 11:16
has joined #pact-jvm

gaurav
2018-07-07 18:30
has joined #pact-jvm


steve.cook
2018-07-08 10:21
has joined #pact-jvm

paisrikanth
2018-07-09 06:19
@uglyog is there a document or an example on how to publish the pacts to the broker from the CI - Jenkins build

uglyog
2018-07-09 09:03
It's the same, nothing special about running from a Jenkins build

gaurav
2018-07-09 15:43
Is there no release: `3.5.19` for `pact-jvm-provider_2.11`? I see `pact-jvm-provider_2.12:3.5.19` in maven repository but can?t find `pact-jvm-provider_2.11:3.5.19`.. :confused:

paisrikanth
2018-07-10 01:31
@uglyog currently i'm do the command ./gradlew pactPublish to upload the files

paisrikanth
2018-07-10 01:32
I want this to run as task.. ex when I run the ciDev it should call the task and upload the files

uglyog
2018-07-10 08:58
let me check for you ...

paulswilliams
2018-07-10 09:12
Regarding this defect, my colleague has simplified the exemplar, and offered a work around fix that further sheds light on the root cause:

paulswilliams
2018-07-10 09:12
Adding ```@BeforeEach public void pause() throws InterruptedException { Thread.sleep(5000L); }``` around tests allows a green run on `master` but not ```@BeforeEach public void pause() throws InterruptedException { Thread.sleep(4500L); }```

uglyog
2018-07-10 09:59
I have re-released the missing jars

uglyog
2018-07-10 10:01
when you say "run as task", what do you mean? Is this a Jenkins thing?

gaurav
2018-07-10 11:55
Thanks @uglyog.. I still don?t see 3.5.19 in maven repository: https://mvnrepository.com/artifact/au.com.dius/pact-jvm-provider_2.11

uglyog
2018-07-10 12:22
It will be a few hours before the indexes are updated

gaurav
2018-07-10 12:49
great! Thanks.

paisrikanth
2018-07-11 00:31
yes Jenkins

paisrikanth
2018-07-11 04:10
@uglyog I get this error FAILED! 409 Conflict - This is the first time a pact has been published for

paisrikanth
2018-07-11 04:53
Quick question ex - my pact directory is "/workspace/app/pact-contracts/" and pact-contracts has two subfolders which has the json files Does the pactPublish all the files under the folder and sub-folders ??

sjani
2018-07-11 05:37
has joined #pact-jvm

uglyog
2018-07-11 09:20
The 409 conflict is because the consumer or provider name is similar to an existing one

uglyog
2018-07-11 09:20
I don't think it will pick up sub-folders

gaurav
2018-07-12 00:13
Its there. :thumbsup:

vinod.baradwaj
2018-07-12 08:34
anyone using https://github.com/warmuuh/pactbroker-maven-plugin this plugin to upload and download pacts from broker ?

vinod.baradwaj
2018-07-12 08:35
when i try to download using the above plugin i get the following error ``` com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 2 column 14 at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1505) at com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1386) at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:531) at com.google.gson.stream.JsonReader.peek(JsonReader.java:414) at com.google.gson.JsonParser.parse(JsonParser.java:60) ... 27 more```

ssn899
2018-07-12 14:09
I did and it also did not work out well. Pact-provider-maven allows testing pacts from a broker (not downloading) https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider-maven#verifying-pact-files-from-a-pact-broker

minhdoan
2018-07-13 03:15
Hi team, anyone has experience with request with space(s) in URL, when executing pactVerify the space should encoded to %20, unfortunately the '+'. I am stuck and don't know how to fix https://github.com/DiUS/pact-jvm/issues/693 Could you please help on it? Many thanks in advance!

vinod.baradwaj
2018-07-13 03:37
okay, let me try with this. Thank you :slightly_smiling_face:

minhdoan
2018-07-13 08:25
Hi team, i am executing pact provider test, the pact-jvm-provider-gradle library is used. My test suite contains 4 test cases (provider MULTI_USERS_PROVIDER has 4 consumers). My system requires login first so we must add an authorization header to each request as below: pact { // Configure the Pact verification log reports { defaultReports() // adds the standard console output json // report in json format } serviceProviders { MULTI_USERS_PROVIDER { requestFilter = { req -> // Add an authorization header to each request // because of our system needs login first with credential: user:password req.addHeader('Authorization', 'Basic dXNlcjpwYXNzd29yZA==') } protocol = providerScheme host = providerHost port = providerPort path = providerScheme + "://" + providerHost + ":" + providerPort + "/webservice" hasPactsFromPactBroker(pactBrokerScheme + "://" + pactBrokerHost + ":" + pactBrokerPort) } } } But in the test suite, there is one test case must use other user , instead of user:password. So i try to use the stateChange for this one: pact { serviceProviders { MULTI_USERS_PROVIDER { requestFilter = { req -> // Add an authorization header to each request // because of our system needs login first with credential: user:password req.addHeader('Authorization', 'Basic dXNlcjpwYXNzd29yZA==') } hasPactWith('AnotherUser_Consumer') { stateChangeUsesBody = false // defaults to true pactSource = url('http://pact-broker-local-repo.net/provider/MULTI_USERS_PROVIDER/consumer/AnotherUser_Consumer/latest') stateChangeRequestFilter = { req -> // Add an authorization header to each request // another:password req.addHeader('Authorization', 'Basic YW5vdGhlcjpwYXNzd29yZA==') } protocol = providerScheme host = providerHost port = providerPort path = providerScheme + "://" + providerHost + ":" + providerPort + "/webservice" hasPactsFromPactBroker(pactBrokerScheme + "://" + pactBrokerHost + ":" + pactBrokerPort) } } } But it seems the credential is not overwritten for specific test case. Anyone has experience on this stuff? Could you please help?

abhilash.hanumanth
2018-07-13 13:36
how do we know the latest version of pact-jvm ?

uglyog
2018-07-15 02:55
@bethskurrie I got the generator working with values returned from the provider state callback


bethskurrie
2018-07-15 21:28
Nice!

minhdoan
2018-07-16 11:48
Hi team, i have a provider with 10 consumers so there are 10 pact records on Broker. And 7 test cases use the default authorization credential, and remaining 3 cases use distinct ones. So i must add requestFilter for each as below code: `'PERMISSION_PROVIDER {` ` requestFilter = { req ->` ` // Add an authorization header to each request` ` // because of our system needs login first` ` //default credential is: superuser:123456` ` req.addHeader('Authorization', 'Basic c3VwZXJ1c2VyOjEyMzQ1Ng==')` ` }` ` protocol = schemeProperty` ` host = hostProperty` ` port = portProperty` ` hasPactsFromPactBroker(brokerScheme + "://" + brokerHost + ":" + brokerPort)` ` // Consumer 1 need the credential: test001:123456` ` hasPactWith('Consumer_1') {` ` pactSource = url('http://localhost/pacts/provider/PERMISSION_PROVIDER/consumer/Consumer_1/latest')` ` requestFilter = { req ->` ` // Add an authorization header to each request` ` // because of our system needs login first` ` // with cre: test001:123456` ` req.addHeader('Authorization', 'Basic dGVzdDAwMToxMjM0NTY=')` ` }` ` }` ` // Consumer 2 need the credential: test002:123456` ` hasPactWith('Consumer_2') {` ` pactSource = url('http://localhost/pacts/provider/PERMISSION_PROVIDER/consumer/Consumer_2/latest')` ` requestFilter = { req ->` ` // Add an authorization header to each request` ` // because of our system needs login first` ` // with cre: test002:123456` ` req.addHeader('Authorization', 'Basic dGVzdDAwMjoxMjM0NTY=')` ` }` ` }` ` ` ` // Consumer 3 need the credential: test003:123456` ` hasPactWith('Consumer_3') {` ` pactSource = url('http://localhost/pacts/provider/PERMISSION_PROVIDER/consumer/Consumer_3/latest')` ` requestFilter = { req ->` ` // Add an authorization header to each request` ` // because of our system needs login first` ` // with cre: test003:123456` ` req.addHeader('Authorization', 'Basic dGVzdDAwMzoxMjM0NTY=')` ` }` ` }` ` }` And i want to ensure that each request will have correct Authorization header info when pactVerify is executed, but i tried with: `gradle pactverify [--info | --debug | -i]` But no option show the Authorization information. Could you please help on it? Many thanks!

dominic.jones
2018-07-17 07:54
has joined #pact-jvm

minhdoan
2018-07-18 04:45
@team Could you please help on it? How do i retrieve detailed information about the request sent to provider when executing pactVerify?

msc.consults
2018-07-18 13:41
has joined #pact-jvm

abhilash.hanumanth
2018-07-20 14:41
I dont think there is a way to intercept the request in provider tests. I am intercepting the request by forwarding the request to provider via proxy. If you know, please let me know

kaushalye
2018-07-23 05:05
has joined #pact-jvm

kaushalye
2018-07-23 05:06
Thanks @uglyog

uglyog
2018-07-23 05:08
The classpath should be the compiled class files

uglyog
2018-07-23 05:09
Can you turn on printing stack traces?

kaushalye
2018-07-23 05:09
<pact.showStacktrace>true</pact.showStacktrace> ?

kaushalye
2018-07-23 05:09
It's already on

kaushalye
2018-07-23 05:12
:point_up: is the trace @uglyog

uglyog
2018-07-23 05:14
It must be a regression. Can you raise a defect for it?


minhdoan
2018-07-23 06:46
I want to build a response with Json format as below: {"value":[ { "attribute": "att1", "url": "/att1" }, { "attribute": "att2", "url": "/att2", "type": "Chemistry" }, { "attribute": "att3", "url": "/att3", "type": "Construction" } ] } I have tried with pact consumer code: .body(new PactDslJsonBody() .minArrayLike("value", 2,2) .object() .stringType("url", "/att1") .stringType("attribute", "att1") .closeObject() .object() .stringType("url", "/att2") .stringType("attribute", "/att2") .stringType("kind", "Chemistry") .closeObject()) But the object() method must have a name: `throw new UnsupportedOperationException("use the object(String name) form");` If using another approach as: .body(new PactDslJsonBody() .array("value") .object() .stringType("url", "/att1") .stringType("attribute", "att1") .closeObject() .object() .stringType("url", "/att2") .stringType("attribute", "/att2") .stringType("kind", "Chemistry") .closeObject()) The format is right, but the actual response body contains more than 3 elements (this is unknown number depends on the test system) in "value" array so verification fails. Could you please help to confirm that the format to build a response as example, whether it is supported in pact V3 or i must wait for the V4? Many thanks and nice day, team!

uglyog
2018-07-23 11:40
`.minArrayLike` automatically starts an object definition, so you don't need the next `.object()` call

uglyog
2018-07-23 11:41
The idea would be to do something like:

uglyog
2018-07-23 11:41
``` .minArrayLike("value", 2,2) .stringType("url", "/att1") .stringType("attribute", "att1") .stringType("kind", "Chemistry") .closeObject() ```

minhdoan
2018-07-23 11:49
@uglyog Thanks, Ron! Because i want to create a "value" array with two different format elements: ``` {"value":[ { "attribute": "att1", "url": "/att1" }, { "attribute": "att2", "url": "/att2", "type": "Chemistry" }]}``` Is it feasible? Or PactDslJsonBody has not supported that type yet?

uglyog
2018-07-23 11:51
The idea with the `Like` matchers is to setup one example that should be like all the elements in the array. It doesn't have a way to define different items in the array.

minhdoan
2018-07-23 12:01
Any enhancement in the future for it? I often face this type in realistic

kaushalye
2018-07-23 23:13
@uglyog I believe with ANNOTATED_METHOD, we do not have to separately run a pact mock service

uglyog
2018-07-23 23:41
Correct, it will call the method directly

kaushalye
2018-07-23 23:50
Thanks. I've raised an issue. (See above). BTW, I am planning to use the pact-jvm-provider-spring as an alternative. Still prefer the maven plugin as it provides a cleaner mechanism. :slightly_smiling_face:

arne.zelasko
2018-07-24 07:02
has joined #pact-jvm

djrimokbp
2018-07-24 10:41
has joined #pact-jvm

ng.viet.quynh
2018-07-24 11:03
has joined #pact-jvm

djrimokbp
2018-07-24 11:59
anyone knows if MockMvcTarget works with controllers using jersey annotations?

uglyog
2018-07-24 22:31
Only if MockMvc works with controllers using jersey annotations. MockMvcTarget just delegates to MockMvc

sguisado
2018-07-25 10:55
has joined #pact-jvm

minhdoan
2018-07-25 11:04
I am writing a pact record for url: http://localhost:8080, so code is as below: ``` return builder .given("Server root URL") .uponReceiving("An request at server root) .path("") .method(HttpMethod.GET.name()) ``` But when run @Test method to create the pact record, failure happens with log: ``` au.com.dius.pact.consumer.PactMismatchesException: The following mismatched requests occurred: Unexpected Request: method: GET path: / query: [:] headers: [Accept:text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2, Connection:keep-alive, Host:localhost:8080, User-agent:Java/1.8.0_161] matchers: MatchingRules(rules={}) generators: Generators(categories={}) at au.com.dius.pact.consumer.junit.JUnitTestSupport.validateMockServerResult(JUnitTestSupport.kt:41) at au.com.dius.pact.consumer.BaseProviderRule.validateResult(BaseProviderRule.java:164) at au.com.dius.pact.consumer.BaseProviderRule$1.evaluate(BaseProviderRule.java:81) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:106) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38) at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:66) at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) ``` I am using **au.com.dius:pact-jvm-consumer-junit_2.11:3.5.19** Could you please help to clarify why the path value could not be set to empty ("")? Many thanks!

antonello
2018-07-25 15:47
has joined #pact-jvm

niedra91
2018-07-26 07:46
has joined #pact-jvm

uglyog
2018-07-26 09:06
The path is not empty, it is coming in as `/`

dipjyotimetia
2018-07-27 04:11
has joined #pact-jvm

dipjyotimetia
2018-07-27 04:12
@here can anyone help me hoy to get started with pact jvm

uglyog
2018-07-27 04:53
@dipjyotimetia start with http://docs.pact.io and then the readmes at https://github.com/DiUS/pact-jvm

mark.bridgett
2018-07-30 12:19
has joined #pact-jvm

mark.bridgett
2018-07-30 12:19
Reposting here: Hey there. Anyone know how I can get my Java provider tests to output the full provider response? I'm trying to debug a failed test and would like to see what my service is sending back that is failing. All I have to go on at the moment is this output which doesn't help much : $.some_property -> [{mismatch=Expected List() to have minimum 1, diff=}]

mark.bridgett
2018-07-30 12:20
I'm guessing it might be an environment variable i need to pass to maven or something. Not a Java dev so none of this stuff is obvious to me (Node.js here)

matt.fellows
2018-07-30 12:51
has joined #pact-jvm

antonello
2018-07-30 14:16
I am interested in the answer as well!

imran.khan2
2018-07-31 07:22
has joined #pact-jvm

imran.khan2
2018-07-31 08:15
Hey folks

imran.khan2
2018-07-31 08:15
I'm trying to run my pact provider tests in CI tool

imran.khan2
2018-07-31 08:16
I'd like it to publish verification resultd to the pact broker

imran.khan2
2018-07-31 08:17
Unfortunately at the moment it publishes the snapshot version (I'm using gradle)

imran.khan2
2018-07-31 08:17
How do I publish in CI with the release version, given verifications seem to only be published during the test phase

imran.khan2
2018-07-31 08:18
?

uglyog
2018-07-31 09:24
Enabling debug level logging will output quite a bit

uglyog
2018-07-31 09:26
You can override the version with configuration in the gradle build file. Check the docs on the github project.

nabrosimova
2018-07-31 17:59
has joined #pact-jvm

nabrosimova
2018-07-31 18:00
Hi, I am trying to figure . out how to use pact_jvm with ruby to do file upload

nabrosimova
2018-07-31 18:01
are there anyone how have used Pact_jvm and ruby got it?

shashidesai
2018-07-31 18:35
has joined #pact-jvm

uglyog
2018-07-31 22:38
Are you trying to test a ruby app with pact-Jvm ? Is this on the consumer or provider side?

nabrosimova
2018-07-31 22:41
both consumer and prover are written in ruby. i need to do file upload api call. and idk how i can do that with pact testing

balthasarbiedermann
2018-08-01 18:31
has joined #pact-jvm

balthasarbiedermann
2018-08-01 18:31
Hi all, is there currently already a Kotlin-specific integration for Pact?

balthasarbiedermann
2018-08-01 18:36
I'm currently playing a bit building a Kotlin-idomatic DSL for Pact. Currently it looks like this: ``` pact { given("serverState") uponReceiving("receivingDescription") with("/foo/bar") { method("PUT") body("{\"name\": \"harry\"}") headers("Authorization", "Bearer sfdlgsl") } willRespondWith { status(200) headers(mapOf("Foo" to "Bar")) } } ```

balthasarbiedermann
2018-08-01 18:39
Is there already something similar?

balthasarbiedermann
2018-08-01 18:39
Feedback is welcome

tushar.gavhane
2018-08-02 04:10
has joined #pact-jvm

abubics
2018-08-02 04:38
I can get close to that with the Java 8 pact consumer

abubics
2018-08-02 04:38
but no, there?s no Kotlin DSL

abubics
2018-08-02 04:40
I keep a base class for pact tests: ``` open class PactBase : StringSpec() { val builder: PactDslWithProvider = ConsumerPactBuilder .consumer("Sample Android App") .hasPactWith("Sample API") private val authToken = "valid_token" val getToken = { authToken } val authHeaders = mapOf("Authorization" to "Bearer $authToken") val contentTypeHeaders = mapOf("Content-Type" to "application/json;charset=utf-8") fun verify(pact: RequestResponsePact, func: ClientConnector.() -> Unit) { val config = MockProviderConfig.createDefault() val result = runConsumerTest(pact, config, object : PactTestRun { override fun run(mockServer: MockServer) { buildClient(mockServer.getUrl(), getToken).func() } }) result shouldBe PactVerificationResult.Ok } } ```

abubics
2018-08-02 04:41
and use it like this: ``` class PactAccountTests : PactBase() { init { "fetches Accounts and converts them to AccountReferences" { val pact = builder .given("a member with some accounts") .uponReceiving("a request for the list of accounts").run { headers(authHeaders) method("GET") path("/member/12345/account") } .willRespondWith().run { headers(contentTypeHeaders) status(200) body(newJsonBody { container -> with(container) { minArrayLike("accounts", 1) { with(it) { stringType("id", "123456") stringType("name", "Test Account 1") stringMatcher("type", "savings|loan", "savings") numberType("availableBalance", 5) numberType("currentBalance", 5.67) } } } }.build()) } .toPact() verify(pact) { fetchAccountList( AccountsRequest( userId = "12345" ) ) shouldBe Response.Success( listOf( AccountReference( id = "123456", type = AccountType.Savings, name = "Access Account TestOne", availableBalance = BigDecimal("5.00"), currentBalance = BigDecimal("5.67") ) ) ) } } ... ```

abubics
2018-08-02 04:42
so you can see it?s a little clunky, but quite close to your example :slightly_smiling_face:

balthasarbiedermann
2018-08-02 07:22
@abubics Thanks for the info and feedback. I like your approach using `run {}`

abubics
2018-08-02 07:22
np :slightly_smiling_face: I?d love to have a native DSL, but I don?t have bandwidth to build it myself :sweat_smile:

balthasarbiedermann
2018-08-02 07:22
Would you use a Kotlin DSL or prefer the `run{}` approach?

abubics
2018-08-02 07:24
`run {}` is ok, but I think it?s avoidable with sugar

abubics
2018-08-02 07:24
and other bits are much worse, like `body(newJsonBody { container -> with(container) {`

balthasarbiedermann
2018-08-02 07:24
That would be the next thing I want to look in

abubics
2018-08-02 07:25
yeah, the object creation dsl in junit8 is ok for java, I guess, but still very boilerplatey in Kotlin :slightly_smiling_face:

abubics
2018-08-02 07:25
it?s certainly better than the plain junit one, which has hard-to-see structure

balthasarbiedermann
2018-08-02 07:26
I'm not sure if I want to keep the fluent approach with the cascading dots in the ConsumerPactBuilder DSL. It does not look so clean and "DSL-like" for me, but provides some compile-time safety

balthasarbiedermann
2018-08-02 07:26
I don't know if I can provide the same safety with the DSL at compile time

abubics
2018-08-02 07:37
the problems I had with it being fluent are more around the different types returned along the pipeline

abubics
2018-08-02 07:37
for example, it changes from `PactDslRequestWithoutPath` to `WithPath`

abubics
2018-08-02 07:38
and all the helpers kinda wanna have parity across them, for ease of use

abubics
2018-08-02 07:38
passing blocks with a `Foo.() -> Bar` type helps avoid the fluent leading dots, though :slightly_smiling_face:

abubics
2018-08-02 07:40
like, I have these helpers for my UI tests: ``` private fun <T : Robot> withRobot(robot: T, func: T.() -> Unit) = robot.apply { isCorrectScreen() func() } fun accounts(func: AccountsRobot.() -> Unit) = withRobot(AccountsRobot(), func) ```

abubics
2018-08-02 07:41
so you still get type safety, but also cleaner code :ok_hand:

abubics
2018-08-02 07:41
oh, maybe I should add the usage sample :stuck_out_tongue: but it *is* like the `run {}` example

abubics
2018-08-02 07:42
e.g. ``` @Test fun transferConfirmTest() { pay { tapTransfer() } nextScreenPayTo { enterAmount("0.88") tapNext() } nextScreenConfirm { verifyAccountDetailsVisible( id = "456", name = "Test One" ) verifyAccountDetailsVisible( id = "987", name = "Test Four" ) verifyAmountVisible("$0.67") tapConfirm() } } ```

balthasarbiedermann
2018-08-02 08:34
Do you use `infix` to get rid of the dots between the function calls? E.g. in `nextScreenPayTo`?


abubics
2018-08-02 08:48
``` infix fun nextScreenPay(func: PayFromToRobot.() -> Unit) = pay(func) ```

balthasarbiedermann
2018-08-02 11:03
I restructured the DSL. This is my new structure idea: ``` kPact { consumer withName "consumer" andProvider "provider" havePact { given providerIsInState "state1" then { whenever receiving "request1" withPath "/path" and { headers("Authorization", "Bearer sfghfsdh") } willRespondWith { body("body") headers(mapOf("Authorization" to "Bearer sfghfsdh")) } whenever receiving "request2" withPath "/path" and { headers("Authorization", "Bearer sfghfsdh") } willRespondWith { body("body") headers(mapOf("Authorization" to "Bearer sfghfsdh")) } } given providerIsInState "state2" then { whenever receiving "request1" withPath "/path" and { headers("Authorization", "Bearer sfghfsdh") } willRespondWith { body("body") headers(mapOf("Authorization" to "Bearer sfghfsdh")) } whenever receiving "request2" withPath "/path" and { headers("Authorization", "Bearer sfghfsdh") } willRespondWith { body("body") headers(mapOf("Authorization" to "Bearer sfghfsdh")) } } } } ```

abubics
2018-08-02 11:21
It's probably a good idea to stick to the same vocabulary where possible, such as `uponReceiving`

abubics
2018-08-02 11:24
I would keep kPact as just pact, because it will probably be in a separate package for import :)

abubics
2018-08-02 11:25
And where you have multiple consecutive infix keywords (e.g. `consumer withName`)... Do they facilitate other mechanisms?

abubics
2018-08-02 11:26
(basically, I'd prefer things to be autocompleteable intuitively... `whenever` doesn't give me much idea what to expect :sweat_smile:)

abubics
2018-08-02 11:27
You could also look to gradle for dsl ideas... But they have several conventions that can be confusing, so be careful ;D)

abubics
2018-08-02 11:29
Looking forward to your body dsl ideas too :D

abubics
2018-08-02 11:29
And, of course, I'm not the only Kotlin Pact user, so don't take my feedback exclusively :P

balthasarbiedermann
2018-08-02 12:09
Naming is a good point. I like the "given..when(ever)..then" schema (I've changed the syntax and the keywords again). But I agree, that consistency is important. Probably you are right and I should ask for more feedback to find a consensus

balthasarbiedermann
2018-08-02 12:10
`consumer withName` and the other similar things are not consecutive infixes. `consumer` is a `val` with the infix function `withName`

balthasarbiedermann
2018-08-02 12:13
auto-completion works with the auto-completion shortcut in IntelliJ also with infix calls. But to let the IDE automatically give you the hint, you should not use the infix notation. I've added shorter non-infix functions for that use-case:

balthasarbiedermann
2018-08-02 12:14
With infix: ``` kPact { consumer withName "consumer" andProvider "provider" havePact { given providerIsInState "state1" then { whenever receiving "request1" withPath "/path" and { headers("Authorization", "Bearer sfghfsdh") } thenRespondWith { body("body") headers(mapOf("Authorization" to "Bearer sfghfsdh")) } whenever receiving "request2" withPath "/path" thenRespondWith { body("body") headers(mapOf("Authorization" to "Bearer sfghfsdh")) } } given providerIsInState "state2" then { whenever receiving "request1" withPath "/path" and { headers("Authorization", "Bearer sfghfsdh") } thenRespondWith { body("body") headers(mapOf("Authorization" to "Bearer sfghfsdh")) } whenever receiving "request2" withPath "/path" thenRespondWith KPact.EmptyResponse } } } ```

balthasarbiedermann
2018-08-02 12:15
Without infix: ``` kPact { consumer("consumer").hasPactWith("provider") { given("state1") { whenever("request1").withPath("/path") { headers("Authorization", "Bearer sfghfsdh") } thenRespondWith { body("body") headers(mapOf("Authorization" to "Bearer sfghfsdh")) } whenever("request1").withPath("/path") .thenRespondWith { body("body") headers(mapOf("Authorization" to "Bearer sfghfsdh")) } } given("state2") { whenever("request1").withPath("/path") { headers("Authorization", "Bearer sfghfsdh") } thenRespondWith { body("body") headers(mapOf("Authorization" to "Bearer sfghfsdh")) } whenever("request1").withPath("/path") .thenRespondWith(KPact.EmptyResponse) } } } ```

balthasarbiedermann
2018-08-02 12:15
The user can use both

balthasarbiedermann
2018-08-02 12:19
What do you think, how to reach as many as possible people to get feedback? Should I open an issue and show the idea of the syntax? Or should I directly open an PR?

balthasarbiedermann
2018-08-02 12:21
The Kotlin DSL evolved. The current state allows a infix syntax and an infix-free syntax. With infix: ``` kPact { consumer withName "consumer" andProvider "provider" havePact { given providerIsInState "state1" then { whenever receiving "request1" withPath "/path" and { headers("Authorization", "Bearer sfghfsdh") } thenRespondWith { body("body") headers(mapOf("Authorization" to "Bearer sfghfsdh")) } whenever receiving "request2" withPath "/path" thenRespondWith { body("body") headers(mapOf("Authorization" to "Bearer sfghfsdh")) } } given providerIsInState "state2" then { whenever receiving "request1" withPath "/path" and { headers("Authorization", "Bearer sfghfsdh") } thenRespondWith { body("body") headers(mapOf("Authorization" to "Bearer sfghfsdh")) } whenever receiving "request2" withPath "/path" thenRespondWith KPact.EmptyResponse } } } ``` Without infix: ``` kPact { consumer("consumer").hasPactWith("provider") { given("state1") { whenever("request1").withPath("/path") { headers("Authorization", "Bearer sfghfsdh") } thenRespondWith { body("body") headers(mapOf("Authorization" to "Bearer sfghfsdh")) } whenever("request1").withPath("/path") .thenRespondWith { body("body") headers(mapOf("Authorization" to "Bearer sfghfsdh")) } } given("state2") { whenever("request1").withPath("/path") { headers("Authorization", "Bearer sfghfsdh") } thenRespondWith { body("body") headers(mapOf("Authorization" to "Bearer sfghfsdh")) } whenever("request1").withPath("/path") .thenRespondWith(KPact.EmptyResponse) } } } ``` Thanks to @abubics for the already provided feedback. One question: Should the typical Pact terminology be used (e.g. `uponReceiving` and `willRespondWith`)? I also like the BDD-like "`given`..`when`(`ever`)..`then`" rhythm. *Feedback is more than welcome.*

matt.fellows
2018-08-02 21:15
I'd refuse an issue as an enhancement request so that it can be done truly in the open. These conversations are great though

uglyog
2018-08-02 23:01
`uponReceiving` and `willRespondWith` is just the current DSL, it should not be mandatory if you can find a better way

uglyog
2018-08-02 23:01
Looks really good to me

abubics
2018-08-03 00:44
I like keeping the existing DSL (or both), unless the new vocab is markedly better :slightly_smiling_face: it helps people switch languages when working from examples. Kotlin has an issue with BDD because `when` is a keyword :stuck_out_tongue:

abubics
2018-08-03 00:46
The non-infix `whenever` damages dsl readability, especially when rendered in the broker :slightly_smiling_face: because `uponReceiving` and `whenever` don?t have the same function in English

abubics
2018-08-03 00:50
I love the direction, though :smile:

cparrish
2018-08-03 18:43
has joined #pact-jvm

tcanascimento
2018-08-07 14:28
has joined #pact-jvm

conallbennett
2018-08-07 22:12
has joined #pact-jvm

antonello
2018-08-08 16:57
I have noticed that when I run the only provider test that we have for now, it takes a long time to publish the verification results. ``` Running com.foo.MyPactTest 2018-08-08 17:25:29,109 aprovider INFO [StandaloneMockMvcBuilder$StaticRequestMappingHandlerMapping] Mapped "{[/endpoint],methods=[GET]}" onto public com.foo.ChannelOutput com.foo.Controller.amethod() 2018-08-08 17:25:29,109 aprovider INFO [StandaloneMockMvcBuilder$StaticRequestMappingHandlerMapping] Mapped "{[/endpoint/venue/{venueId}],methods=[GET]}" onto public com.foo.ChannelOutput com.foo.Controller.amethodForVenueId(java.lang.Long) 2018-08-08 17:25:29,110 aprovider INFO [StandaloneMockMvcBuilder$StaticRequestMappingHandlerMapping] Mapped "{[/endpoint/{channelCode}],methods=[GET]}" onto public com.foo.ChannelOutput com.foo.Controller.amethodByChannelCode(com.foo.ChannelCode) 2018-08-08 17:25:29,127 aprovider INFO [RequestMappingHandlerAdapter] Looking for @ControllerAdvice: org.springframework.test.web.servlet.setup.StubWebApplicationContext@1603a2a1 2018-08-08 17:25:29,132 aprovider INFO [MockServletContext] Initializing Spring FrameworkServlet '' 2018-08-08 17:25:29,132 aprovider INFO [TestDispatcherServlet] FrameworkServlet '': initialization started 2018-08-08 17:25:29,134 aprovider INFO [TestDispatcherServlet] FrameworkServlet '': initialization completed in 2 ms Verifying a pact between aconsumer and aprovider Given ........ has a matching body (OK) 2018-08-08 17:26:09,393 aprovider INFO [ProviderVerifier] Published verification result of 'true' for consumer 'Consumer(name=aconsumer)' Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 40.517 sec - in com.foo.MyPactTest ``` Time elapsed 40s, most of which seem to spent publishing the results. It seems far too much time.

kurst03
2018-08-09 00:29
has joined #pact-jvm

uglyog
2018-08-09 08:48
@antonello Wow, that is long. It is just doing a post request to the broker, it shouldn't take that long.

antonello
2018-08-09 08:48
I wonder what it is?

antonello
2018-08-09 08:49
Would there be any interesting TRACE or DEBUG level logging worth enabling?

uglyog
2018-08-09 08:50
Definitely. If you enable debug logging for the Apache HTTP client, you should see the actual request being made.

gaurav
2018-08-11 08:09
Hello all, I am evaluating mockMvc in a spring project. I have a scenario where a contract expects 404 for certain request. For that request, provider service throws an exception with 404 status: `throw new MyException("Unable to execute the request", 404)` and pact test fails with following:

gaurav
2018-08-11 08:09
I would expect pact test not to fail.

uglyog
2018-08-11 08:09
If the code under test throws an exception, you need to handle it.

gaurav
2018-08-11 08:09
how can I handle this?

gaurav
2018-08-11 08:10
Thats a stateless test. :confused:

gaurav
2018-08-11 08:10
so don?t know where to catch that exception.

uglyog
2018-08-11 08:10
Oh, in the provider test. Bummer.

gaurav
2018-08-11 08:12
Anything that can be done? otherwise will have to add state in consumer tests. And probably will be able to catch exception in method that implements state?

uglyog
2018-08-11 08:14
The spring exception handlers should be handling that. You might just have to configure the MockMvc to handle the exception

gaurav
2018-08-11 08:16
spring exception handlers do that when application is running.. Not sure how mockMvc will handle them. will look into that. mockMvc is bit new to me :slightly_smiling_face: Thanks a lot.

gaurav
2018-08-11 08:51
got it.. just needed to add a Controlleradvice that was handling exceptions globally. :slightly_smiling_face:

gaurav
2018-08-13 06:49
In mockmvc example at https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider-spring, There is a comment: `We cannot autowire this as we're not using (and don't want to use) a Spring test runner.` I am just being bit curious about why using spring test runner is a bad choice. :slightly_smiling_face:

lindblad.n
2018-08-13 07:30
has joined #pact-jvm

lindblad.n
2018-08-13 08:27
Hi! Posting here, as I?m not sure where this issue occurs - if it?s a Pact Broker configuration thing, a maven plugin bug, or an expected behavior. I?m trying to use the `pact-jvm-provider-maven_2.12` plugin to connect to a Pact Broker, but it seems the base URL is being changed somewhere which causes the execution of `mvn:verify` to fail. The issue is that I?m specifying ?https://<base_url>/<rest_of_path>?, but it?s being changed to ?http://<base_url>:443/<rest_of_path>? and doesn?t seem to follow redirects... Maven plugin settings: ``` <plugin> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-provider-maven_2.12</artifactId> <version>3.5.20</version> <!--mvn pact:verify--> <configuration> <serviceProviders> <serviceProvider> <name>a</name> <pactBroker> <url>https://pact.somecompany.net/</url> <serverId>pact-broker</serverId> <!-- This must match the server id in the maven settings --> </pactBroker> </serviceProvider> </serviceProviders> <pactBrokerUrl/> <!-- To suppress the warning --> </configuration> </plugin> ``` Execution results: ``` service-a git:(master) ? mvn pact:verify [INFO] Scanning for projects... [INFO] [INFO] ---------------< com.somecompany.a:service-a >--------------- [INFO] Building service-a 1.0.3 [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- pact-jvm-provider-maven_2.12:3.5.20:verify (default-cli) @ service-a --- Verifying a pact between b and a [from Pact Broker http://pact.somecompany.net:443/pacts/provider/a/consumer/b/version/1.0.0-SNAPSHOT] [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4.120 s [INFO] Finished at: 2018-08-13T09:37:42+02:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal au.com.dius:pact-jvm-provider-maven_2.12:3.5.20:verify (default-cli) on project service-a: Execution default-cli of goal au.com.dius:pact-jvm-provider-maven_2.12:3.5.20:verify failed: Request to path 'http://pact.somecompany.net:443/pacts/provider/a/consumer/b/version/1.0.0-SNAPSHOT' failed with response 'HTTP/1.1 400 Bad Request' -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException ```

lindblad.n
2018-08-13 08:30
Publishing to the same server with `pact-jvm-provider-maven_2.12` and the same server url and serverId settings works fine, and it looks like the plugin is finding pacts between the services, only failing to fetch the files

uglyog
2018-08-13 08:33
That comments comes from the days before the Pact spring runner, and it is referring to the default spring runner

lindblad.n
2018-08-13 08:34
Relevant parts of Stacktrace: ``` Caused by: au.com.dius.pact.pactbroker.RequestFailedException: Request to path 'http://pact.somecompany.net:443/pacts/provider/a/consumer/b/version/1.0.0-SNAPSHOT' failed with response 'HTTP/1.1 400 Bad Request' at au.com.dius.pact.pactbroker.HalClientBase$getJson$1.invoke (HalClient.kt:227) at au.com.dius.pact.pactbroker.HalClientBase$getJson$1.invoke (HalClient.kt:126) at au.com.dius.pact.provider.broker.com.github.kittinunf.result.Result$Companion.of (Result.kt:110) at au.com.dius.pact.pactbroker.HalClientBase.getJson (HalClient.kt:211) at au.com.dius.pact.pactbroker.HalClientBase.fetch (HalClient.kt:202) at au.com.dius.pact.pactbroker.HalClientBase.fetch (HalClient.kt:197) at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod (IndyInterface.java:232) at au.com.dius.pact.provider.broker.PactBrokerClient.fetchPact (PactBrokerClient.groovy:121) at au.com.dius.pact.model.PactReaderKt.loadPactFromUrl (PactReader.kt:32) at au.com.dius.pact.model.PactReader.loadFile (PactReader.groovy:189) at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod (IndyInterface.java:232) at au.com.dius.pact.model.PactReader.loadPact (PactReader.groovy:28) at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod (IndyInterface.java:232) at au.com.dius.pact.provider.ProviderVerifier.loadPactFileForConsumer (ProviderVerifier.groovy:115) at au.com.dius.pact.provider.ProviderVerifier.runVerificationForConsumer (ProviderVerifier.groovy:79) at au.com.dius.pact.provider.ProviderVerifier.runVerificationForConsumer (ProviderVerifier.groovy) ```

uglyog
2018-08-13 08:38
The URL used to fetch the pact file is the one it would have got from the broker, so it is either your broker not configured correctly, or a proxy in front of it that is doing that

lindblad.n
2018-08-13 08:39
Ok, so the broker sends back the ?base url? used to fetch the files? Thanks a lot, and sorry if i cluttered up the channel


amitojduggal
2018-08-13 15:07
has joined #pact-jvm

gaurav
2018-08-14 01:03
I see.. thanks.

gaurav
2018-08-14 02:59
I am getting error while running provider test: `Expected 'application/json;charset=utf-8' to match 'application/json;charset=UTF-8'` On consumer side, I see following in pact file: ```{ "match": "regex", "regex": "application/json;charset=UTF-8" }``` And on producer side, content type is produced as: `produces = "application/json;charset=UTF-8"` I can get around this by changing UTF-8 => utf-8 on consumer side or by defining a regex to match both lower and upper case on consumer side. However because as per RFC2045, content type value should be case insensitive, do you think it should be handled by pact (don?t match case for content-type value)? https://tools.ietf.org/html/rfc2045#page-12

paul.davies
2018-08-14 04:19
has joined #pact-jvm

paul.davies
2018-08-14 04:20
Hi all, I'm pretty new to Pact and have checked the Stack Overflow but no luck with my problem. I'm having an issue with a Date query parameter which is handled by a DateTime argument resolver at runtime. When debugging my application I can hit the endpoint with this command: GET http://localhost:9090/plan/master/active?from_start_date=2018-08-01T22:00:00.000Z and I can see the date has been correctly interpreted, however when I run my Pact Provider test, which has this in the Pact contract:

paul.davies
2018-08-14 04:20
The date comes through as null

paul.davies
2018-08-14 04:21
My endpoint

paul.davies
2018-08-14 04:22
Any assistance would be most welcome. Thanks!

paul.davies
2018-08-14 04:23
OptionalDateTimeParam

paul.davies
2018-08-14 04:23
OptionalDateTimeArgumentResolver

antonello
2018-08-14 12:49
Is there a built-in way of skipping the publishing pacts when using the the maven plugin? I?m asking because I wouldn?t want to publish pacts when running `mvn verify` locally (unless I actually decide to)

amitojduggal
2018-08-14 13:10
i usually do it this way, specify this as part of provider plugin config ```<configuration> <pact.showStacktrace>true</pact.showStacktrace> <pact.verifier.publishResults>${pact.verifier.publishResults}</pact.verifier.publishResults> </configuration>```

amitojduggal
2018-08-14 13:10
and then override it using a property in maven

amitojduggal
2018-08-14 13:11
``` <pact.verifier.publishResults>false</pact.verifier.publishResults>```

amitojduggal
2018-08-14 13:11
and then from the console you can mvn pact:verify -Dpact.verifier.publishResults=true

amitojduggal
2018-08-14 13:12
or false, as you may like

antonello
2018-08-14 13:20
@amitojduggal That is to publish verification results

antonello
2018-08-14 13:20
I am talking about publishing pacts

antonello
2018-08-14 13:25
There does not seem to be an equivalent property to skip the `pact:publish` goal.

gaurav
2018-08-14 13:35
@antonello `mvn pact:verify` is done on provider side to verify pacts and `mvn pact:publish` is done on consumer side after pacts are generated by consumer tests e.g. unit tests. So you run your consumer tests in usual way e.g. `mvn clean test` which runs tests and pact files are generated during tests. They won?t be published to pact broker unless you do `mvn pact:publish`

antonello
2018-08-14 13:42
@gaurav we publish the pacts as part of the mvn `verify` phase.

antonello
2018-08-14 13:44
Perhaps we shouldn?t do that.

gaurav
2018-08-14 13:51
yeah.. remove that if you don?t want to publish pacts on each run. Its better to publish pacts only when tests look fine.. otherwise, depending on setup, it might make provider tests fragile. I run `pact:publish` as a separate step.

antonello
2018-08-14 13:51
well, on CI you always want to publish them

antonello
2018-08-14 13:51
we don?t use `pact-jvm-provider-maven_2.12` to do provider verification by the way

gaurav
2018-08-14 13:53
yes, on CI: if tests look good -> publish pacts in next step. thats how I do.

antonello
2018-08-14 14:00
that is what we implicitly do, as you don?t get to the maven verify phase if the test phase failed

antonello
2018-08-14 14:01
the issue is that once you?ve bound the pact:publish goal to the verify phase, you can?t easily skip it.

antonello
2018-08-14 14:09
There is an easy workaround, which is to set phase to none, but I was just wondering if you could skip it in any other way, although it seems there isn?t.

antonello
2018-08-14 14:11
Something that @uglyog should be able to confirm.

gaurav
2018-08-14 14:31
I do it in simple way (don?t bind pact:publish to verify phase): step 1: Run tests | step 2: `mvn pact:publish`. step 2 won?t be executed if step 1 fails in CI. Simple. No issues.

uglyog
2018-08-14 22:32
Is there a reason you are matching the content type explicitly? Pact-JVM will check the content type matches, because it needs it to know how to parse the body

uglyog
2018-08-14 22:35
Debug logs will help

uglyog
2018-08-14 22:39
Yeah, I never conceived someone wanting to invoke the publish task and have it do nothing :smile:

uglyog
2018-08-14 22:39
There is no don't publish option.

paul.davies
2018-08-14 23:50
Thanks @uglyog will attach now. Not sure how much use these will be but it's the console output from running my pact test.

paul.davies
2018-08-14 23:58
Hi all, Is there something special i need to do for java.util.Date query values? If I switch the controller parameter to a String and then perform the conversion to a date later on, my Pact provider test will work fine. This will be a big refactor to do this so will be a 'last resort' option. Could this be done via a ValueResolver within the MockMvcTarget by any chance? An example of how this is done would be most welcome. Thanks in advance.

paul.davies
2018-08-15 02:09
No drama. A colleague of mine worked it out. As we have some custom configuration within our SpringBoot application we needed to run the test via a SpringRestPactRunner combined with SpringBootTest. Also we needed to use an HttpTarget rather than the MockMvcTarget so that the pact test is pointed towards the application booted by the SpringBootTest. Thanks for offering to help @uglyog!

nick
2018-08-16 03:18
has joined #pact-jvm

rrosa
2018-08-17 09:25
has joined #pact-jvm

kristine.jetzke
2018-08-18 18:35
has joined #pact-jvm

kristine.jetzke
2018-08-18 20:28
Hi, I?m using pact junit to publish my contracts to the broker. I noticed that the broker detects a contract change every time I upgrade to a new version of pact-jvm. I assume it?s because the pact contains the pact-jvm version. Is that correct? Is there a specific reason that the version needs to be included in the pact file? If not I would file a PR and remove it.

uglyog
2018-08-19 02:42
It's for diagnostic purposes, so when someone submits a pact file with an issue, we know what created it. Maybe a better option would have the broker ignore the metadata, or to have an option to strip it out when publishing

kristine.jetzke
2018-08-19 14:23
Yes, I would also prefer if the broker would ignore the metadata. I can prepare a PR for that. Do you know if the pact spec version (which is also part of the metadata) needs to be included?

kristine.jetzke
2018-08-20 18:32
Might have been fixed already according to this: https://github.com/pact-foundation/pact_broker/issues/147 I will check again after I have upgraded the broker

kristine.jetzke
2018-08-20 18:40
I need to set `base_equality_only_on_content_that_affects_verification_results` to true in the config.

komalahluwalia06
2018-08-23 07:23
has joined #pact-jvm

rsaccoll
2018-08-27 13:27
has joined #pact-jvm

abhilash.hanumanth
2018-08-28 11:23
Did anyone face this problem in provider tests ?

uglyog
2018-08-28 11:59
Check the version of Scala that you are running with.

abhilash.hanumanth
2018-08-28 12:32
@uglyog: I am using gradle pact-jvm

abhilash.hanumanth
2018-08-28 12:34
```contractTestImplementation (group:'au.com.dius', name:'pact-jvm-provider-junit_2.12', version:'3.5.16', transitive: true)```

abhilash.hanumanth
2018-08-28 14:30
Guys someone please help me

abhilash.hanumanth
2018-08-28 14:30
I am not getting anything because of above error

abhilash.hanumanth
2018-08-28 14:31
which scala libraries I should use for PACT. I didnt define anything explicitly. I am using latest pact-jvm

abubics
2018-08-29 00:34
Your messages were between 10:30pm and 12:30am here :slightly_smiling_face: most of the contributors are asleep or not working at that time

ashish.dubey91
2018-08-29 03:26
cross-posting from #general: I'm noticing an issue in my CI setup with pact involving the hosted pact broker. here is how it is - with pact-jvm and gradle plugin I'm pushing my pacts with the branch name as the tag (edited) when I fetch the pacts from this url `/pacts/provider/API/consumer/android/latest/dev` I get the latest pact published from *any* branch rather than specifically `dev` branch always because of this my provider build fails because of unstable contracts pushed in feature branches of the consumer

ashish.dubey91
2018-08-29 03:26
does anybody know what could be wrong here?

uglyog
2018-08-29 03:35
What other libraries are you using? Make sure that all rely on Scala 2.12

abubics
2018-08-29 03:36
what does the `pact {}` block look like in your `build.gradle`?

abhilash.hanumanth
2018-08-29 04:39
ok ok :slightly_smiling_face: Please help me Boris

ashish.dubey91
2018-08-29 04:41
``` pact { publish { pactDirectory = 'xxxxx/target/pacts' pactBrokerUsername = 'xxxxxxx' pactBrokerPassword = 'xxxxxxx' pactBrokerUrl = 'https://xxxx.pact.dius.com.au' tags = ["${branchName}"] version = appVersionName } } ```

abubics
2018-08-29 05:25
that's in the consumer, how about the provider's `build.gradle`?

abubics
2018-08-29 05:29
I haven't seen this error before, I don't have any quick fixes

abubics
2018-08-29 05:30
additionally, I haven't used the `contractTestImplementation` DSL either :upside_down_face:

abubics
2018-08-29 05:32
If @uglyog's hopeful direction is right, you could try changing `_2.12` to other Scala versions, and see if it changes your errors

abubics
2018-08-29 05:33
if you can't work it out like that, the best way to get help is to make a simple public repo that reproduces your issue, so someone can help work through your code

ashish.dubey91
2018-08-29 05:39
I'm running provider verification using python-pact's pact-verifier


abubics
2018-08-29 05:44
that's not a #pact-jvm question, then :slightly_smiling_face:

abubics
2018-08-29 05:45
I haven't done any Pact stuff with Python, sorry

abubics
2018-08-29 05:45
good luck ^_^

ashish.dubey91
2018-08-29 05:52
Okay this seemed to me pact-jvm and pact broker issue because even if I fetch `/pacts/provider/API/consumer/android/latest/dev` which should reflect only the pact pushed from the `dev` branch

ashish.dubey91
2018-08-29 05:53
but when I fetch it I receive the pact pushed from differen tbranch

ashish.dubey91
2018-08-29 05:53
so I guess it's less of a pact-verifier issue

ashish.dubey91
2018-08-29 05:55
does it make sense?

abhilash.hanumanth
2018-08-29 06:48
Can you please tell me what all scala libs are used in pact so that i will force to use those libraries of scala 2.12 in my gradle for contract tests

abubics
2018-08-29 07:22
I'm not sure if that's how tags work in the ReST API . . . your expectation might be right

abubics
2018-08-29 07:22
but I just use the gradle plugin, and I never see what endpoint it uses :slightly_smiling_face: so I can't really tell you

ashish.dubey91
2018-08-29 07:57
okay. I got this from the documentation of pact broker

ashish.dubey91
2018-08-29 08:00
according to the documentation it should work like I'm expecting it..either I misunderstood something and there is a bug

ashish.dubey91
2018-08-29 13:38
can we even have different pacts for the same version but different tags?

abubics
2018-08-29 14:18
You can publish different pact payloads with the same version. The version is tagged, so you can't get different tags :)

ashish.dubey91
2018-08-29 14:18
okay I think I got it all wrong

ashish.dubey91
2018-08-29 14:20
this was happening: a ci build on dev branch was pushing a pact with version=4.1 and tag=dev. on a different branch a pact with version=4.1 and tag=feature-something was being published

ashish.dubey91
2018-08-29 14:21
when I fetch latest version with dev, it fetches me version=4.1 which is overwritten by pact from feature-something branch

david.j.smith
2018-08-29 14:30
has joined #pact-jvm

ashish.dubey91
2018-08-29 14:49
thanks for the help @abubics!

mpasumarthy
2018-08-29 16:08
has joined #pact-jvm

uglyog
2018-08-29 22:29
Pact is built with Scala 2.12 (hence the _2.12 in the module names)

abubics
2018-08-30 02:03
no worries :slightly_smiling_face: if you haven't seen it already, there's a "Show latest tags" action in the top-right of the broker landing page UI. That might help consolidate your mental models

madhukar.mishra
2018-08-30 05:41
has joined #pact-jvm

madhukar.mishra
2018-08-30 05:45
Hello, trying to represent an array with different types in pact, haven't been able to find how to model that in pact-jvm. Here are further details https://stackoverflow.com/questions/52089816/how-to-represent-responses-with-heterogenous-arrays-in-pact-jvm

abhilash.hanumanth
2018-08-30 08:20
Thanks @uglyog . It works after forcing scala version to 2.12 in gradle

ibenardetelevis
2018-09-04 07:11
has joined #pact-jvm

thirumal.net
2018-09-06 18:11
has joined #pact-jvm

minhdoan
2018-09-14 09:32
Hi team, i want to run pactVerify (using pact-jvm-provider-gradle 3.5.9) with two providers as below snippet

minhdoan
2018-09-14 09:35
But it seems when any first provider's record failed, it willl stop the pactVerify task. Any configuration to ignore failure and continue remaining tests? Many thanks for your reading and help!

malheur
2018-09-18 08:07
has joined #pact-jvm

malheur
2018-09-18 08:10
Hi all, I'm running CDC test on provider's side and facing the problem: https://stackoverflow.com/questions/52359563/pact-provider-tests-broken-pactverificationtesttemplate-preconditionviolation. What should I do to make the consumer-broker-provider bundle work together. Additionally: the running pact-broker, when I'm opening a contract, displays the warning: "this contract could not be parsed to a v1 or v2 Pact, showing raw content instead". Thanks in advance!

adam
2018-09-19 13:11
has joined #pact-jvm

uglyog
2018-09-23 04:47
I've given an initial answer on SO. The broker only renders V1 or V2 pacts, but Pact-JVM defaults to V3. That is just a rendering issue, they will still work ok with the broker.

yudinagata
2018-09-24 23:21
has joined #pact-jvm

yudinagata
2018-09-24 23:25
hello, I'm trying to validate a pact on the provider side in a junit test, but I'm getting the following error.

abubics
2018-09-25 00:05
as in, `NoSuchMethodError: matchHeaders`?


uglyog
2018-09-25 22:36
Check the version of the Scala libraries in your classpath. Pact-JVM has to run with the same versions of Scala as it has in the JAR names (i.e. if you use pact-jvm-consumer-junit-2.12) it has to use Scala 2.12

yudinagata
2018-09-26 17:38
thank you, that fixed the problem

viktor.nyblom
2018-09-27 07:47
has joined #pact-jvm


uglyog
2018-09-28 01:13
Yeah, it is all @bethskurrie's fault: https://github.com/DiUS/pact-jvm/issues/738

uglyog
2018-09-28 01:18
I have answered the SO question

matt.fellows
2018-09-28 01:31
lol

matt.fellows
2018-09-28 01:31
thx

bethskurrie
2018-09-28 09:13
Lies!

dervis4
2018-10-03 13:47
Hi guys, do you have any idea why my example provider app publishes the verification results automatically? I have set the pact.verifier.publishResults variable through Maven to false, but the results are still being published. Source code: https://github.com/dervism/person-provider

dervis4
2018-10-03 13:51
Getting this in the log: 13:49:31.459 [main] DEBUG au.com.dius.pact.provider.junit5.TestResultAccumulator - All interactions for Pact person-provider-person-consumer are verified 13:49:31.461 [main] DEBUG au.com.dius.pact.pactbroker.HalClientBase - Posting JSON to https://norwegianlga.pact.dius.com.au/pacts/provider/person-provider/consumer/person-consumer/pact-version/df604a7296cab416741e83acca146eeedaea346c/verification-results {"success":true,"providerApplicationVersion":"1.0"} 13:49:32.549 [main] DEBUG au.com.dius.pact.pactbroker.HalClientBase - Got response HTTP/1.1 201 Created

uglyog
2018-10-03 22:14
Are you running the latest version of Pact-JVM?


dervis4
2018-10-04 08:16
I tried running with "mvn clean install -Dpact.verifier.publishResults=false" but it still publishes... The same happens in my build server.

fraser.crichton.devel
2018-10-04 23:22
has joined #pact-jvm

arne.zelasko
2018-10-10 09:43
hi , we currently use dropwizard and spring boot for creating microservices. some om my colleagues has the idea to use spring boot contract instead of pact-jvm. is it possible to use spring boot contract and pact-jvm togerther, so that for an example the consumer is a dropwizard service which uses pact and the provider is a spring boot service which uses spring cloud contract or the other way around ?

uglyog
2018-10-10 09:44
I believe spring cloud contract supports pacts files, so it may be possible

arne.zelasko
2018-10-10 09:48
okay maybe i look there in the documentation

dagarwal
2018-10-10 11:04
has joined #pact-jvm

alejandro.exequiel.ca
2018-10-17 19:46
has joined #pact-jvm

avi.pardu.nash3
2018-10-21 23:31
has joined #pact-jvm

inbox
2018-10-23 23:34
has joined #pact-jvm

kanohen
2018-10-24 08:25
has joined #pact-jvm

kanohen
2018-10-24 08:39
Hello guys, Please, I have a pact test on my producer. The producer is a Gradle spring project. I have added the pact test to a pact directory in my test folder. When I run ./gradlew test --info, every test in the test folder runs except the pact test. For some reason Gradle isn't aware of that test. However , when I run it locally, without using Gradle, it works fine. Is there some configuration I need to add to my build file to notify Gradle of the pact folder?

nishantv12
2018-10-24 08:50
has joined #pact-jvm

nishantv12
2018-10-24 08:55
Hi all, I am writing my first pact provider test in my organization for a Spring Boot API . We have a pact broker setup which requires SSL. I am not able to find an option for specifying the trust-store in annotation. Do i need to use maven plugin along with the pact-jvm-provider-spring library?

abubics
2018-10-24 10:32
Ssl isn't part of the interface contact, just the transport. You don't need to assert anything, just use http in the tests :)

abubics
2018-10-24 10:45
Also, can y'all add an avatar, or whatever? It's hard to follow when everyone has the same default icons...

abubics
2018-10-24 10:46
What does "run it locally, without using Gradle" mean? Like, from your IDE?

kanohen
2018-10-24 11:13
I mean when I use the runner

kanohen
2018-10-24 11:13
It works but when I use the Gradle --test, the test is skipped.

kanohen
2018-10-24 11:20
Also, I am not getting notification anytime someone replies to my posts/replies from slack. So I have to check back to see if a reply has been dropped. No push notification.

nishantv12
2018-10-24 11:21
Thanks for the response. But I am talking about the SSL for pact broker and not the API under test. The pact broker has been setup in such a way that it requires SSL connection. But your reply made me realise that the particular section i was referring to in maven plugin is for providers and not broker. So I just want to know if I can specify truststore while connecting to broker

uglyog
2018-10-24 11:49
Not sure what you mean by "I use the runner". Do you mean the PactRunner used with the `@RunWith` annotation?

uglyog
2018-10-24 11:53
If it is regular SSL it will work. If you require MASSL, then I don't think that will work. You can add the certificates to the JVM truststore if you are using self-signed certificates.

kanohen
2018-10-24 12:18
@uglyog yes.

kanohen
2018-10-24 12:33
Oh @uglyog I think your answer is NO. What I mean is when you write a test, next to the test method or class, you can run that particular set of classes or methods. There is functionality that says 'run the tests' kind of. That works fine. The problem is when I try to run the tests in a build plan e.g using Gradle with my jenkins/bamboo plan, the test fails. So far I have added the @TestTemplate which causes the test to he seen but now I have to write a method for the @TestTemplate method. I now ask what the @PactVerifyProvider do? Does it verify if the provider obeys the contract?

nishantv12
2018-10-24 12:55
@uglyog thanks. I added the required certificates to the JVM truststore and it worked for me. I guess that's the only way

kanohen
2018-10-24 12:59
Ok, getting even closer to the problem. Gradle is only going to run a test if it finds the @Test or @TestTemplate annotations. I really don't need this as I just run the test with Gradle when I don't have @Test or @TestTemplate annotations. Is there a way to force Gradle to run a pact test even if it doesn't have those annotations?

alex
2018-10-24 15:37
has joined #pact-jvm

inbox
2018-10-24 16:55
Looking to use PACT-JVM to validate Kafka events. Are there any examples around. Ideally Spring Boot . Kotlin . ?

abubics
2018-10-24 23:51
There is definitely some amount of support for messaging (e.g. Kafka, SQS, etc), but I personally don't know where good examples are. Maybe this is a starting point? https://github.com/pact-foundation/pact-message-demo

abubics
2018-10-24 23:53
Or maybe @tom.hombergs's own blog post? https://reflectoring.io/cdc-pact-messages/

abubics
2018-10-24 23:55
I've never tried to verify a provider in a unit-testing style, so I can't really help with that.


uglyog
2018-10-25 00:27
You have to use the test annotations. It's the only way to indicate your class is a test. Otherwise it's just a class and the test runner will ignore it

tom.hombergs
2018-10-25 03:14
has joined #pact-jvm

kanohen
2018-10-25 16:31
When I run on on my intellij IDE it does verify the contract is obeyed. The issue is when I then try to run it with Gradle, it fails. I added this plugin called springbootutility and now I can see it hitting the test when I run ./gradlew pactVerify

kanohen
2018-10-25 16:36
The only issue is I needed a way to start my spring project , verify the pact and then shut or terminate the task again. This was what the plugin was supposed to do and it is but I think I am not setting things up properly. When I remove the start provider task and terminate provider task, it does calls my test class and tries to verify the pact except it fails because my spring project isn't started. Error localhost:8080 connection failed is returned. However, when I add the startProvider(bootRun), the app is started on localhost:8080 but the pact task is then not called because my application runs infinitely. I read it is because bootRun task extends the standard Gradle javaExec task, which is not able to run in the background. It was then suggested that one should try the springbootutility.

inbox
2018-10-25 16:55
@abubics thanks for the shares yesterday

uglyog
2018-10-25 21:27
ah, I see. `./gradlew pactVerify` doesn't run tests. It verifies the pact files itself. If springbootutility works, use it. I have also used the spawn plugin to run the app in the background (it won't work on windows)

anfalsiddiqui
2018-10-29 21:16
has joined #pact-jvm

anfalsiddiqui
2018-10-29 21:20
Hello! We have been running into an issue in IntelliJ with pact-jvm. When we add the maven dependency, intellij is able to properly import the library, but is unable to run _anything_. It isn't showing any errors, but no tests, classes files, etc. can be run; the run button greys out. Has anyone encountered this issue before?

anfalsiddiqui
2018-10-29 21:21
Here are the dependencies we are adding

abubics
2018-10-30 00:19
What kind of app are you building?

abubics
2018-10-30 00:19
(I haven't seen that type of issue before)

kristine.jetzke
2018-10-30 07:18
We encountered it a while ago. I think we ?solved? it by upgrading the kotlin plugin

anfalsiddiqui
2018-10-30 17:51
Thanks @kristine.jetzke, that seems to have done the trick!

borsuk.artem034
2018-10-31 13:59
has joined #pact-jvm

borsuk.artem034
2018-11-02 13:41
Hi, can I use Pact with SQS message broker?

uglyog
2018-11-02 23:11
@borsuk.artem034 you can using message pacts. Have a read through https://dius.com.au/2017/09/22/contract-testing-serverless-and-asynchronous-applications/

joscha.alisch
2018-11-03 16:26
has joined #pact-jvm

joscha.alisch
2018-11-03 16:34
Hi there :slightly_smiling_face: Just started using pact-jvm-junit and I'm a bit confused on how to verify multiple interactions on the consumer side. It seems like it is necessary to test all the interactions in a *single* unit test annotated with `@PactVerification`. When trying to separate the calls to the mock-server into multiple tests I get `au.com.dius.pact.consumer.PactMismatchesException: The following requests were not received: ... ` on all of them. Having a single test of course is fine for all the examples I've encountered in tutorials where there are only a small amount of interactions. However once you have more than that, the test gets very long and hard to understand. Is there any way of splitting them up?

joscha.alisch
2018-11-03 16:36
I've also tried a different route of defining multiple pacts - but then it seems impossible to use the same consumer-name for all of them, as the pact-json file just gets overwritten by the last of the pacts.

uglyog
2018-11-03 21:40
You can use multiple test classes. The pact files will be merged together, but you must ensure that each test has a unique description for the interaction.

uglyog
2018-11-03 21:43
The one caveat is the mock server will check every request it receives, so you need to define all the expeceted interactions. If you leave any out, you will get a failure about non-received requests.

joscha.alisch
2018-11-03 21:52
> The pact files will be merged together Indeed they do. I must have had the same description when testing this earlier - thanks @uglyog :unicorn_face:

iryna.feuerst
2018-11-05 13:14
has joined #pact-jvm

borsuk.artem034
2018-11-05 14:31
and I got error

jbbarquero
2018-11-05 20:14
has joined #pact-jvm

jbbarquero
2018-11-05 20:17
Hello, message repeated from the general channel, but my issue is about publishing to a pact broker using the maven plugin in a JVM application (Java)

jbbarquero
2018-11-05 20:18
Is it possible to specify a trustore for publishing pact files into a Pact Broker with HTTPS with certificates issued by a custom CA? I don?t find the option at https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider-maven#publishing-pact-files-to-a-pact-broker

xcq1.defy
2018-11-06 09:28
has joined #pact-jvm

iryna.feuerst
2018-11-06 16:55
Hi everyone! I?m using the ConsumerPactBuilder in my Java Consumer application. I would like to define a request parameter (like /my/path?my_param=example_value). I assume that I should use the query-method of the ConsumerPactBuilder.PactDslWithProvider.PactDslWithState.PactDslRequestWithoutPath. I cannot find a simple documentation about how properly to pass in the part ?my_param=example_value?. Could anybody help me with that or point to the right documentation?

iryna.feuerst
2018-11-06 17:01
Oh, I can just pass it as it is to query(?my_param=example_value?). That was too simple to be evident :slightly_smiling_face: . Sorry for disruption

jonas.natten
2018-11-15 08:17
has joined #pact-jvm

cosmin.mogos
2018-11-29 11:02
has joined #pact-jvm

ruben.perezg
2018-11-29 14:57
has joined #pact-jvm

andrew.nicholson
2018-12-03 18:01
has joined #pact-jvm

andrew.nicholson
2018-12-03 18:44
Hello - I am trying to figure out how to use the jvm-consumer-junit library to define a matcher that is an array of arrays, where: * the outer array has at least 1 element * the inner arrays all have at least 1 element * the inner array entries are strings the closest thing that I have is: ``` .eachArrayWithMinLike("outerArray", 1) .stringType("exampleString") .closeArray() ``` but the inner array doesn't seem to have an 'at-least-one' matcher....can someone provide some advice?

andrew.nicholson
2018-12-03 18:47
I have also tried: ``` .eachArrayWithMinLike("outerArray", 1) .minArrayLike(1, PactDslJsonRootValue.stringType("exampleString")) .closeArray() .closeArray() ``` but then I end up with an extra level of nesting

uma.shanker
2018-12-06 16:25
has joined #pact-jvm

sthan
2018-12-07 18:36
has joined #pact-jvm

mpasumarthy
2018-12-11 03:37
Hi, Could someone guide/help me... I have followed the steps mentioned in https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider-spring#example-of-mockmvc-test I'm using pact-jvm-provider-maven_2.12 version 3.6.0 plugin to verify the results. Junit is running fine, but I am seeing the below issue when I run mvn pact:verify goal..

mpasumarthy
2018-12-11 06:08
I am not able to publish results back to pact broker, could you guide me how to set "pact.provider.version" and publish the results

abubics
2018-12-11 06:23
If there's someone in here using maven . . . I think most people use gradle (and I'm not sure what the maven integration looks like)

uglyog
2018-12-11 07:29
@mpasumarthy You can use the `-D` parameter to Maven, i.e. `mvn -Dpact.provider.version=1.0.0 pact:verify` or you can use the configuration section of the Pact Maven plugin. See https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider-maven#plugin-properties

antonello
2018-12-11 10:15
When is it likely that we?ll get a new release of `pact-jvm`? Wondering when we could get https://github.com/DiUS/pact-jvm/pull/828 in :slightly_smiling_face:

joaquin.delgado
2018-12-11 14:04
has joined #pact-jvm

joaquin.delgado
2018-12-11 14:39
Hi! I'm trying to implement the definition of an array of n elements via lambda DSL: "componentsIds": [ "A1" ] or "componentsIds": [ "A1", ... "An" ] so far I've tried: (LambdaDslObject) category.eachLike("componentsIds", modelOptionIdsArray -> modelOptionIdsArray.stringType()); and (LambdaDslObject) category.eachKeyLike("componentsIds", modelOptionIdsArray -> modelOptionIdsArray.stringType()); and (LambdaDslObject) category.eachArrayLike("modelOptionIds", modelOptionIdsArray -> modelOptionIdsArray.eachLike(a -> a.stringType()); But none of them are parsed. Only the fixed .array("componentsIds", modelOptionIdsArray -> modelOptionIdsArray.stringType()); is working. Anyone has a lead on how to do this?

mpasumarthy
2018-12-11 17:12
Thanks..it worked but i added this to sure-fire maven plugin...

uglyog
2018-12-11 21:21
I'll push out a release this weekend, probably on Sunday

uglyog
2018-12-11 21:30
@joaquin.delgado looks there is no implementation for eachLike with an array of primitives. The DSL is expecting an object in the array. Can you raise an issue for this?

joaquin.delgado
2018-12-12 06:36
sure thing!

james.carman
2018-12-13 02:19
has joined #pact-jvm

rworcest
2018-12-14 01:07
has joined #pact-jvm

rworcest
2018-12-14 16:28
3.5.14 of pact-jvm-provider-junit_2.12 and pact-jvm-consumer-junit_2.12 I'm trying to setup pact in a middle layer (a BFF): APK - pact file - BFF - pact file - backend How can I make a junit test that is both a @Provider and has @PactProviderRuleMk2? Doing the obvious thing runs the provider test normally but ignores the @Pact method. Do I need junit 5? Do I need to do something weird to use multiple test runners or junit rules?

rworcest
2018-12-14 17:31
Or maybe there's some other annotations for a test that's both a provider and consumer. I read https://docs.pact.io/best_practices/provider#stub-calls-to-downstream-systems which had no information and the linked gist which seemed to be about how to mock out part of the code by hand without using a pact file

rworcest
2018-12-14 17:43
https://docs.pact.io/getting_started/provider_states says that states can be used to stub a downstream system (no further details). https://stackoverflow.com/questions/46183190/pact-using-provider-state shows how to use state but it seems like a hack to parse the pact file here since I want this for all states and shouldn't have to parse/validate pact files myself (even with builders)

rworcest
2018-12-14 17:50
The junit and junit5 versions of ContractTest in pact-jvm shows a provider stubbing a backend by hand rather than by using a pact file

uglyog
2018-12-14 22:59
@rworcest are you trying to test the entire chain from the first BFF to the end service in one test? Pact is design to test one interaction at a time.

rworcest
2018-12-15 00:02
@uglyog I suppose it is 2 interactions but it isn't the entire chain since what the backend calls isn't involved (there are more than 3 layers). But how am I supposed to test the APK to BFF interaction while having a realistic stub of my backend except by using the second pact file? If the backend updates the BFF to backend pact file how can the APK to BFF stubs be kept in sync to make sure the APK doesn't become broken?

rworcest
2018-12-15 00:48
You made it sound like it isn't possible to have a junit test that is both a provider and consumer. Is there any way to make pact work for my BFF? We're looking to replace our in house library which is based on VCR so a solution that isn't great may still be better than what we have now.

uglyog
2018-12-15 07:18
There are a few ways of mocking a service using a pact file. Have a look at something like https://github.com/pact-foundation/pact-stub-server

rworcest
2018-12-15 15:19
Thanks for the info but in order to run all tests on a build server I'll need each test to specify the stubbing required. I found https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider#an-example-of-running-provider-verification-with-junit and while I don't understand everything it is doing it looks like the junit test is parsing the pact file. Is there any way I can feed a list of RequestResponseInteraction to an internal class that is used by PactProviderRuleMk2 to create a mock service?

ruben.perezg
2018-12-17 08:03
Hi! I have a question regarding `pact-jvm`, and I am not sure if this is the right place for it. If it?s not, excuse me, and please let me know how should I do it :slightly_smiling_face: We are starting a _PoC_ with Pact in our java ecosystem, and I have started with consumer tests. I have a few of them, and they execute successfully when they are run in an isolated way (just one test at a time). But when I try to execute all the tests together (all of them are located in the same test class), then only the first one executed succeeds, and the rest fail with a `Connection refused` exception (_java.net.ConnectException_). My client is implemented using _OpenFeign_, and I?m using `pact-jvm-consumer-junit5_2.12-3.6.0` and `pact-jvm-consumer_2.12-3.6.0` . And these are the annotations that I have in my test class: ``` @ExtendWith(PactConsumerTestExt.class) @PactTestFor(providerName = "productMs") ``` Probably this is a beginner mistake, but I?m quite stuck with it?

uglyog
2018-12-17 08:22
@ruben.perezg try using a random port for each test. Your HTTP client may be caching the connections. Each test gets a new mock server, so if the client has cached the connection, it will be stale for the later tests

ruben.perezg
2018-12-17 08:52
How could I do that?

ruben.perezg
2018-12-17 08:53
In each test I?m using an annotation like this: `@PactTestFor(pactMethod = "createProductPact")` If I?m not specifying the port, shouldn?t it be random?

uglyog
2018-12-17 10:22
Yes. How are you setting the port on the http client?

uglyog
2018-12-17 10:24
You can, but you'll have to write the code to do that yourself. That is basically what the junit test module does for you.

ruben.perezg
2018-12-17 10:26
using `mockServer.getUrl()` directly

ruben.perezg
2018-12-17 10:27
with the _MockServer mockServer_ parameter of the test method

uglyog
2018-12-17 10:31
And you are not setting a port in the test?

ruben.perezg
2018-12-17 10:34
what do you mean by that? AFAIK, with the annotation `@PactTestFor`, there will be a random port assigned if you don?t choose one. That?s what I am assuming, whether that?s true or not :slightly_smiling_face: And I?m using that to create the client for the tests


ruben.perezg
2018-12-17 10:35
> The @PactTestFor annotation allows you to control the mock server in the same way as the JUnit 4 PactProviderRule. It allows you to set the hostname to bind to (default is localhost) and the port (default is to use a random port). You can also set the Pact specification version to use (default is V3).

ruben.perezg
2018-12-17 10:49
and I can confirm now (I have tested it now) that each test method is getting a different port in my case

ruben.perezg
2018-12-17 10:50
but the port used by my http client somehow is always the same? So it looks like I?m doing something wrong creating my client :man-shrugging:

ruben.perezg
2018-12-17 13:59
I?m gonna dig deeper in my client issue, but I would like to change the approach a bit. I think it would be better overall if I could use the same port for all my test methods inside a given class. If I wanted to use the same port for all the tests in my test class, how should I do it? AFAIK, I need to use the `@PactTestFor` annotation in each test method, so I can specify what `fragment` I?m gonna use in that specific test. But doing that, I get a random port for each one? Is there a way for me to use the same port in every test method of a given class?

nishantv12
2018-12-17 14:40
Hi. I am new to pact testing and trying to understand the best practices when writing pacts for Consumer and Provider which are two different teams and do not share database. Do we need to agree on the existence of valid data at both ends? This doesn't sound right to me. But in case when consumer calls the provider with some query parameters as well as header parameters which should also be returned in the response, is providing provider state and then parse it to create an appropriate mocked state the best way?

erik.moller
2018-12-17 15:23
has joined #pact-jvm

erik.moller
2018-12-17 15:27
Hi, we using Pact at my company and got a question from a team that sending http delete message with a request body and couldn't get the provider test to work..after a bit of investigation I realized that it wasn't possible with the current http apache client library, the org.apache.http.client.methods.HttpDelete does not support body....what is your thoughts there?

rworcest
2018-12-17 17:06
I'd rather minimize duplicating library code. The way that a consumer test uses @PactProviderRuleMk2 didn't work for my provider test. Is there a way a provider test can use @PactProviderRuleMk2? If not what classes can I use?

rworcest
2018-12-17 17:37
(Technically it's @Rule with a new PactProviderRuleMk2 since PactProviderRuleMk2 isn't an annotation).

uglyog
2018-12-17 21:32
You can specify the same port, use the `port` attribute on the `@PactTestFor` annotation

uglyog
2018-12-17 21:34
You can put the annotation on both the class level and method level. It will use what's specified at the method level and default to the class level.

uglyog
2018-12-17 21:36
Some HTTP methods generally don't support bodies. You'll have to check the HTTP RFC on the DELETE method, but I would expect that if the Apache HTTP client is not sending the body then that is probably the case.

uglyog
2018-12-17 21:39
That's the best way we could find to solve this problem. If you have a better idea, we would love to hear it. But I believe that teams collaborating on integration points is the best way to build integrated systems.

erik.moller
2018-12-17 22:43
I saw for example Elastic Search Client, created their own delete with a body, and also we are using spring framework as our backend/provider which supports a body for delete...so it's little different depending on which library/framwork you are using. But, I think pact should actually send the delete with body and then let the provider test decide if that is valid or not

erik.moller
2018-12-17 22:48
`` private static class HttpDelete extends HttpEntityEnclosingRequestBase { public HttpDelete(URI uri) { super(); setURI(uri); } @Override public String getMethod() { return "DELETE"; } } ``

erik.moller
2018-12-17 22:51
This "formatted" code is from Spring Web Client, I could create a PR for it?

erik.moller
2018-12-17 22:55
The scenario now is: - No problem pushing a delete request with a body to p-broker - The test runs no problem, the request gets sent to the http-target, but the body is not included and the test fails with error code 400, that is also very hard for a user to actually understand that the reason was because the body in the request was omitted,

erik.moller
2018-12-17 22:56
Either way I think it should be some change, add support for body in delete or else fail earlier in the chain

ruben.perezg
2018-12-18 07:25
After struggling yesterday with a few things, I will try to post here what I found: - We thought about using the same port for all test methods because of performance reasons: the first request of our client library (OpenFeign) takes forever, so we didn?t want that to happen for every request? But we have found a workaround for that, so we don?t need that anymore. - Our client was _indeed_ catching different things (connections, configuration) under the hood, even though it was hard to find. - I know that setting a hardcoded value for the port at the class level will make all the test methods use that port. - What I don?t know is how can we use *the same random port* in every test, so that it can run in any local machine and in our CI environments without the flakyness of trying to use an already in use port. If that?s possible, could you let me know how to do that? I?m still not sure if that?s the way to go or not, because it looks like there is a new wiremock ?instance? under the hood for every test method anyway? (not sure about that)

uglyog
2018-12-18 08:58
You could do that in code. By default if you provide a port of 0, the OS will assign a port from the available ports. You could open a port in the setup, then close the connection, and then use that for all the tests. But you won't be able to set that port for the mock server without extending the PactConsumerTestExt class.

uglyog
2018-12-18 09:02
The connection details are created in a "before" handler using a `ProviderInfo` class. If `PactConsumerTestExt` was extended to allow that object to be injected, you could inject it into a "beforeEach" method and set the port to a random one.

uglyog
2018-12-18 09:06
By using the same random assigned port for each test may still be an issue. For more info, have a look at this issue: https://github.com/DiUS/pact-jvm/issues/342#issuecomment-258594453

nishantv12
2018-12-18 09:28
good to know thanks

nishantv12
2018-12-18 09:44
When running provider tests do we usually mock the database repository or set up a database instance and mock data for the test? I like the idea of mocking as it brings it closer to unit test. But wanted to know the practices in general

ruben.perezg
2018-12-18 11:09
Thank you very much for all your help @uglyog :slightly_smiling_face:

james.carman
2018-12-18 14:09
I?m using mocking

james.carman
2018-12-18 14:09
you?re only trying to test the contract, so it really doesn?t matter where the data comes from

james.carman
2018-12-18 14:09
makes setting up @State very simple (just train the mock)

rworcest
2018-12-18 19:32
Here's a small code sample of what I'm trying to do (this doesn't work). Ideally this would create the pact file BFF_Locator-Foundational.json, use that file as a stub service, and run the provider test. What's the minimum amount of coding I'll need to get this to work? Maybe a different Target implementation? I can also provide the APK-BFF_Locator.json pact file which is what the provider is testing against but I didn't think it was relevant.

nishantv12
2018-12-20 15:48
Thanks for the response. I did the same. But I found several examples online where at the provider end they just start the real API with real database in place or pointing to an environment. I believe pact tests should be as close as possible to unit tests

james.carman
2018-12-20 18:22
I?m with you and I believe I?ve had folks give me the same advice here on slack. I?m certainly not the expert, though.

nishantv12
2018-12-21 08:40
From one of the consumers we are getting a pact file with query string as a map ```"query": { "?`queryParamKey": [ "valuex%3Avaluey%3Avaluez%2Cvaluea%3Avalueb%3valuec" ] }``` At the provider side this is not getting parsed with the error `groovy.lang.MissingMethodException: No signature of method: static au.com.dius.pact.model.PactReader.queryStringToMap() is applicable for argument types: (groovy.json.internal.LazyMap)`

nishantv12
2018-12-21 08:41
I am using pact-jvm version 3.5.16 at the provider end

guidopio.mariotti10_d
2018-12-29 23:44
has joined #pact-jvm

nishantv12
2018-12-31 10:16
Hi, I believe my query was lost in the holidays. But would really appreciate any information regarding this issue.

uglyog
2018-12-31 23:18
That is not a valid query parameter. It should not start with the ```?` ```

uglyog
2018-12-31 23:18
It also should not cause that failure

nishantv12
2019-01-01 09:56
thanks. but the query params being provided as a map is a valid syntax?

rworcest
2019-01-01 16:20
https://stackoverflow.com/questions/53978159/how-to-start-a-mock-server-in-my-providerservice-and-call-a-webservice links to https://docs.pact.io/best_practices/provider#only-stub-layers-beneath-where-contents-of-the-request-body-are-extracted which states "If you do need to stub something (eg. a downstream system), make sure that you only stub the code that gets executed after the contents of the request body have been extracted and validated." Is there any way I can get pact to stub the downstream system and validate it?

uglyog
2019-01-01 23:44
yes, V3 format pact files use a map for query parameters

nishantv12
2019-01-02 12:06
oh ok thanks. i will check the specification for any further such details.

nishantv12
2019-01-02 12:28
so I removed the `?` symbol before query param and tried to run the provider tests. However I am still getting the same error `groovy.lang.MissingMethodException: No signature of method: static au.com.dius.pact.model.PactReader.queryStringToMap() is applicable for argument types: (groovy.json.internal.LazyMap)` If I upgrade the *pact-jvm-provider-spring* version from *3.5.16* to *3.6.1* in order to match with the version used by the consumer, I am getting this error- `java.lang.NoClassDefFoundError: au/com/dius/pact/provider/spring/SpringEnvironmentResolver` eventhough the required dependencies are available in my classpath.

rworcest
2019-01-02 14:33
@uglyog have you had a chance to look at the above code? What are your thoughts on my situation?

nishantv12
2019-01-03 15:17
looks like there was a dependency for pact_jvm_provider_jnuit 3.5.16 specified in some other dependency. Had to use <exclusions> in my pom to exclude any other pact dependency and prevent dependency conflicts with 3.6.1

uglyog
2019-01-04 05:04
@rworcest You can use a mock/stub server for test. These are servers that can return fixture responses so your integration works.

uglyog
2019-01-04 05:05
You can use wiremock in Java, but there are other examples.

vinod.baradwaj
2019-01-04 06:11
is it possible to add `pact-jvm-provider` tests using `testng` ?

rworcest
2019-01-04 16:05
I am not familiar with wiremock but that is something we could look into. Two quick questions: 1. Does that provide a way to stub responses based on the existing pact files? I didn't find anything like that (wiremock-pact-generator appears to be the other way around). 2. Alternatively what classes can I use (possibly from the junit test module) to get pact to stub the service within my Provider test?

thomas.scheuchzer
2019-01-05 10:18
has joined #pact-jvm

nishantv12
2019-01-09 12:16
is this the right channel to ask questions for *scala-pact* or is there a different dedicated channel?

mboudreau
2019-01-09 23:00
yep. We don't have a lot of scala requests, so it doesn't deserve it's own channel just yet :slightly_smiling_face:

jonas.natten
2019-01-10 09:18
There is a #pact-scala-itv channel, but it isn't very active

nishantv12
2019-01-10 16:07
ok then i will probably ask the question here.

rworcest
2019-01-10 16:29
I talked with someone about pact and it seems I misunderstood the scope and intention of pact. I was hoping to use pact to replace a library which is based indirectly on VCR (https://github.com/vcr/vcr). The library we are currently using we call the AST framework. AST tests are run over the entire project's code base whereas Pact is only for API verification (and should not run implementation code). The pact doc https://github.com/pact-foundation/pact-ruby/wiki/FAQ#how-does-pact-differ-from-vcr doesn't mention that pact doesn't run as much of the code base compared to vcr (assuming the java versions act the same as the ruby ones) which is either good or bad depending on use case. @uglyog thanks for your time. I'll figure out what to do from here.

abubics
2019-01-10 22:19
You're right that that's not the intended scope :slightly_smiling_face: but VCR can also test as much or as little of your code as you like. It just depends what you stub in your tests.

gbivins4
2019-01-12 00:24
has joined #pact-jvm

nishantv12
2019-01-15 10:14
Just wanted to inform that `protocol` for *pactbroker* doesn't seem to work even with version *3.5.24* in *pact-jvm-provider-spring*. I had to use `scheme` to make it work.

antonello
2019-01-15 13:48
I have split the provider tests for a given consumer/provider into different classes, one class per endpoint under test (let?s say 2), and therefore splitting the various `@State` methods into 2 classes. However, when the provider tests run, each of the 2 provider test classes tries to verify all interactions defined in the pact. Naturally, some fail because not all `@State` methods are defined in each class. The only way to get around it is by having a `@PactFilter` in each class, with only the states you are implementing in said class. This, however, seems a bit odd, as you end up repeating ?magic strings? in more than one place. Is there any other way of doing this that I?m not seeing?

nishantv12
2019-01-15 15:25
Can't think of a way but if the tests are getting this big then I would probably treat each endpoint as a different provider within the same service

slack1977
2019-01-17 14:19
has joined #pact-jvm

galvinshane
2019-01-18 11:47
has joined #pact-jvm

uma.shanker
2019-01-22 12:24
Can someone provide guide/reference/sample for simple consumer and provider test over kafka message queue?

nishantv12
2019-01-28 10:09
I have a high level question around testing SSL related contracts between microservices. These requirements are "contracts" because you need to agree on this in order to get the services talk to each other. If you think about it these contracts are actually provider driven and not consumer driven. So I am not sure if CDD or Pacts can actually help. Or can they? I wanted to understand how do people generally test that.

matt.fellows
2019-01-29 05:25
This is possibly a good question for #general, but I usually don?t test SSL as part of contract tests. They aren?t related to the payload, and this kind of testing is unlikely to pick up any useful bugs (if people are just testing local/self-signed certs I don?t think it proves anything you can?t test easily with other means)

matt.fellows
2019-01-29 05:25
that being said, people ask for it enough, and we have support for it (mostly) across the toolchain

dagarwal
2019-01-29 12:04
~Hello guys , when i add pact matching with term here on path withRequest: { method: ?GET?, path: term({ matcher: ?/api/assets/[0-9]+?, generate: ?/api/assets/10006? }), }, ( I am getting 404 when i try to load the data on UI :disappointed: ) .Without adding matcher it just works fine for me . Any suggestions on what went wrong and how to achieve it ?~

vicenzo
2019-01-29 22:42
has joined #pact-jvm

vicenzo
2019-01-29 22:45
Anyone around to help me figure out a problem I have with my provider?

vicenzo
2019-01-29 22:46
On my `build.gradle` I?ve added: ```plugins { id "au.com.dius.pact" version "3.6.1" } subProjects { apply plugin: 'au.com.dius.pact' testCompile 'au.com.dius:pact-jvm-provider-gradle_2.12:3.6.1' }```

vicenzo
2019-01-29 22:47
on one of the subprojects (the one I should have a pact with) ```#build.gradle pact { serviceProviders { 'sentinel-judge' { hasPactsFromPactBroker('http://d1lrubypactappdev1.local/') } } } ```

claudia.cordes.de
2019-01-30 13:27
has joined #pact-jvm

vicenzo
2019-01-30 23:17
No one have any idea how to fix my problem?

abubics
2019-01-31 02:07
Looks like this is the relevant bit out of that stack trace: ``` Caused by: java.lang.NoSuchMethodError: org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(Ljava/lang/Iterable;Lgroovy/lang/Closure;)Ljava/util/List; at au.com.dius.pact.provider.ProviderVerifier.runVerificationForConsumer(ProviderVerifier.groovy:60) at au.com.dius.pact.provider.ProviderVerifier.runVerificationForConsumer(ProviderVerifier.groovy) at au.com.dius.pact.provider.ProviderVerifier.verifyProvider(ProviderVerifier.groovy:36) at au.com.dius.pact.provider.gradle.PactVerificationTask.verifyPact(PactVerificationTask.groovy:40) at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75) ... ```

vicenzo
2019-01-31 06:01
wonder of this is a bug with pact or my project being dumb :/

abubics
2019-01-31 07:37
Yeah, I haven't used 3.6.1, so I couldn't tell you :slightly_smiling_face:

abubics
2019-01-31 07:38
Also not sure about your combination of `plugins` and `subprojects` blocks . . . I can't tell if there's anything wrong with it, I haven't tried that combo before

vicenzo
2019-01-31 14:49
it looks like it works, but I've been reading more about it and I will change to the dependency format

vicenzo
2019-01-31 16:44
any suggested version to fall bacl to?

vicenzo
2019-01-31 19:01
FYI bumped down to 3.5.14 and it works

gopinathlangote11
2019-02-01 13:09
Any plan for implementing `pact-jvm-kotin `?

james.carman
2019-02-01 22:20
you can?t use the regular one from Kotlin?

james.carman
2019-02-01 22:24
or are you looking for a nicer DSL that Kotlin may be able to provide?

uglyog
2019-02-03 00:54
I'll have a look

uglyog
2019-02-03 03:25
It's a bug with Groovy `@CompileStatic` in the verifier. I have removed the annotation.

gopinathlangote11
2019-02-04 14:11
Yes. I can use but it will be nice, if there is nicer Kotlin build in support available

abubics
2019-02-05 00:25
Yeah, @gopinathlangote11 & @james.carman, until someone feels like putting effort into a nicer DSL for Kotlin, the junit-java8 DSL is the least bad to use :slightly_smiling_face:

abubics
2019-02-05 00:26
With a liberal dosing of Kotlin sugar, you can make it quite legible, e.g.


gopinathlangote11
2019-02-05 09:03
@abubics I agree. We can use java-8 till then. If we start with adding kotlin dsl, people can add to it later

keetron
2019-02-05 10:38
has joined #pact-jvm

keetron
2019-02-05 10:38
I am trying to have my pact files written someplace else than `/target/pact`, we will have a pact broker in a few weeks but want to do some POC before that and I cannot find how to do this

keetron
2019-02-05 10:39
My inability to find how does not mean it is not there, just that I cannot locate the correct documentation...

dipeshlpatel
2019-02-05 11:22
has joined #pact-jvm

jlopespereira
2019-02-05 14:12
has joined #pact-jvm

james.carman
2019-02-05 16:43
is there a flag to use on the maven plugin to tell it to skip publishing the pact files to the broker?

james.carman
2019-02-05 16:43
I know I?ve seen it before, but can?t find it now.

abubics
2019-02-05 23:36
There's an option in the gradle plugin to change the output directory . . . let me find it

abubics
2019-02-05 23:39
```systemProperty 'pact.rootDir', "$buildDir/pacts"```

abubics
2019-02-05 23:39
So, a system property called `pact.rootDir`, and set it to whatever path you like :slightly_smiling_face:

keetron
2019-02-06 08:03
that is what I was looking for, thanks

keetron
2019-02-06 08:04
I also discovered this information is in the Readme, but only after cloning the jvm code and doing a search on the default location

keetron
2019-02-06 08:31
I am now working on my first provider / consumer combination, and ran into something

keetron
2019-02-06 08:32
the `@State` annotation basically should set the state for whatever possible contract can come in? Or does it need to fit a certain explicit contract?

james.carman
2019-02-06 11:31
@keetron the @State annotation is intended to set up a pre-determined, specific state or perhaps provide a template (via the Map parameter) for a specific type of state. I wouldn?t consider that a ?set up any state you want? type facility.

james.carman
2019-02-06 11:34
Basically, keep it reasonable and controlled

keetron
2019-02-06 11:35
ok, thank you. Right now I am struggling with getting the service to run at all using JUnit5, but I will keep you updated.

james.carman
2019-02-06 13:22
I?m on junit4. What sort of issues are you facing?

keetron
2019-02-06 13:42
oh, nothing with pact, but local setup and running of the service

keetron
2019-02-06 13:43
`@Rule` was removed from JUnit5, I have troubles migrating

dipeshlpatel
2019-02-06 21:03
Hello everyone, I am new to PACT and was wondering if someone can point out if there is any video series which i can follow or attend PACT workshop in London to gain better understanding to implement using JAVA. Referred the link below but i guess step by step docs/video that is what i need ; https://github.com/DiUS/pact-workshop-jvm

jlopespereira
2019-02-07 10:07
Hi everyone, I wanted to ask something about Pact. We are using contract testing already for our integration tests but we wanted to see if we could re-use the contracts to build a mocked server of the provider to be used in our component testing. Is this something that someone has tried to do? I was wondering if there would a way to initialize this mocked server at the beginning of our component tests

gopinathlangote11
2019-02-07 14:26
I have tried this way

gopinathlangote11
2019-02-07 14:27
Let me know in specific if i can help you :slightly_smiling_face:

vicenzo
2019-02-07 21:13
glad to be able to submit a bug report on the wrong place :) but glad that it was fixed

keetron
2019-02-08 08:11
I would say you?d like to avoid using pact tests for functional verification

petro.turovskyy
2019-02-09 18:51
has joined #pact-jvm

jlopespereira
2019-02-11 14:02
@keetron you mean, not using the contracts from the pact tests to build a mocked server to use it on our component testing?

keetron
2019-02-11 14:06
Well, the thing is that pact is designed to show technical implementation regression when it occurs.

keetron
2019-02-11 14:06
On the pact page it explicitly points out that testing API functionality is to be avoided

keetron
2019-02-11 14:07
and I would imagine that using your pact files as some sort of API definition would make it tempting to extend the pact test itself outside of the scope of the intention

jlopespereira
2019-02-11 14:07
Yes, exactly

jlopespereira
2019-02-11 14:07
That was my idea

jlopespereira
2019-02-11 14:07
See if I could take advantage of it

jlopespereira
2019-02-11 14:08
But if it's not recommended or if people tried that and it didn't work, I might avoid doing it

keetron
2019-02-11 14:11
If you separate the mock?s technical implementation (that you build using pact contracts) from the functional data (your actual tests) and not put the functional data in the contracts, I think it would work

keetron
2019-02-11 14:11
if you build it generic, it might not even be a bad idea :wink:

jlopespereira
2019-02-11 15:18
I'll try that :slightly_smiling_face: Thanks @keetron!

keetron
2019-02-12 11:49
For some reason, the pact consumer generated contract does not contain the headers that are send by the consumer. Did I do a setting wrong?

james.carman
2019-02-12 12:05
What does your pact definition look like?

keetron
2019-02-12 12:13
you mean the json?

keetron
2019-02-12 12:15
or the java?

gopinathlangote11
2019-02-12 12:18
Where are your setting consumer headers?

keetron
2019-02-12 12:30
I am under the impression the consumer header was captured by the pact provider stub, but appears not?

keetron
2019-02-12 12:31
and I tried setting up checks on consumer headers but could not figure out where

james.carman
2019-02-12 12:32
You need to declare it in your pact

james.carman
2019-02-12 12:32
It doesn?t ?record? it while talking to the stubbed service

james.carman
2019-02-12 12:33
The pact is created by the DSL


keetron
2019-02-12 12:34
can you point me to a syntax source for java? or an example?

keetron
2019-02-12 12:34
on how to set consumer headers?

keetron
2019-02-12 12:35
after which I would happily RTFM :wink:

james.carman
2019-02-12 12:44
Here?s one of my examples: ``` @Pact(provider = PROVIDER, consumer = CONSUMER) public RequestResponsePact createNoNameFragment(PactDslWithProvider builder) { return builder .uponReceiving("Hello") .path("/hello") .method("POST") .matchHeader("Content-Type", "application/json") .body(newJsonBody(o -> o.stringValue("name", "Pact") ).build()) .willRespondWith() .status(200) .matchHeader("Content-Type", "application/json") .body(newJsonBody(o -> o .stringType("greeting", "Hello, Pact!") ).build()) .toPact(); } ```

james.carman
2019-02-12 12:44
notice the matchHeader

james.carman
2019-02-12 12:46
The cool thing is that the pact framework will keep you honest. For example, if you add ```matchHeader("foo", "bar")```, but you don?t send a ?foo? header, it will throw an AssertionError

keetron
2019-02-12 12:53
yeah, I wanted to implement that but was not aware it is called `matchHeader`

keetron
2019-02-12 12:53
awesome! Thank you!

keetron
2019-02-12 12:53
Now I can close this story, it was being a pain

keetron
2019-02-12 13:00
weirdly tho, the `matchHeader` is actually causing an error 500

keetron
2019-02-12 13:00
in my consumer

keetron
2019-02-12 13:01
while I would expect it to be just for checking consumer headers and not influencing consumer behavior?

keetron
2019-02-12 13:06
oh, I was doing something wrong myself

sam
2019-02-13 17:43
has joined #pact-jvm

mail
2019-02-20 11:05
has joined #pact-jvm

vicenzo
2019-02-22 19:48
Good mornjng

vicenzo
2019-02-22 19:48
i am a little dumb folded by the error being generated by the verifier on the provider

vicenzo
2019-02-22 19:48
could someone try and help me please?

vicenzo
2019-02-22 19:49
the value is the same and it is still failing?

james.carman
2019-02-22 20:19
perhaps one is a string and one is a number?

vicenzo
2019-02-22 20:59
no :/

vicenzo
2019-02-22 20:59
when I change a key to string on the client the provider expected a '0' but got 0

vicenzo
2019-02-22 21:05
could it be that those numbers on java are big decimals?

vicenzo
2019-02-22 21:45
fixed it by generating the response on the client with marchers

damien.castelltort
2019-02-26 17:28
has joined #pact-jvm

dagarwal
2019-03-06 17:14
Hi , I am using my contract test like this on consumer side describe(?Getting available action for publish?, () => { before(() => { return provider.addInteraction({ given: ?GET call?, uponReceiving: ?Get available action?, withRequest: { method: ?GET?, path: ?/api/actions%3Fcontext%3Dtype%3Btype%3Dpublish%3BassetIds%3D10212? }, willRespondWith: { status: 200, headers: { ?Content-Type?: ?application/json? }, body: actions } }); }); it(?Get available actions for publish?, () => { return request.get(`http://localhost:${PORT}/api/actions%3Fcontext%3Dtype%3Btype%3Dpublish%3BassetIds%3D10212`) .set({ ?Accept?: ?application/json? }).then((response) => { return expect(Promise.resolve(response.status)).to.eventually.equals(200); }).catch(err => { console.log(?Error in available actions?, err); }); }); }); and its generating the json correctly ,Data under body part is exactly the same what i see on hitting api on provider side But validation is failing since when it is matching, order is changed .I can see all those values present even while verification is done but no order is followed To make it simple : at provider side /api/user1 { id :1, name: abc } { id:2, name:xyz } and i add exactly same data at consumer side But when provider verification happens it is not following the order and compares id 1 with some other id 2 What am i missing here ?

abubics
2019-03-06 23:39
what is in `actions`? it probably needs flexible matchers, if the body doesn't use them already

dagarwal
2019-03-07 11:30
it looks like this


dagarwal
2019-03-07 11:30
@abubics

dagarwal
2019-03-07 11:34
@matt.fellows can you suggest something

aidamanna
2019-03-07 14:39
has joined #pact-jvm

abubics
2019-03-07 23:23
so, it seems like you're using `like()` wrong

abubics
2019-03-07 23:24
as far as I remember, it only takes one object to describe the shape, but you're passing several objects of the same shape as separate parameters

abubics
2019-03-07 23:25
btw, what timezone are you in? we seems to always respond 12 hours apart :stuck_out_tongue:

matt.fellows
2019-03-07 23:27
Looks like the UK, maybe

dagarwal
2019-03-08 09:18
yes UK :stuck_out_tongue_winking_eye:

dagarwal
2019-03-08 09:20
but then how else can i add matchers if i want to pass multiple objects ?

msc.consults
2019-03-09 11:06
Hi everyone, I've written a pact contract test in groovy for a negative scenario (i.e. I make a `POST` request that's invalid and expect a `400` status to return. This all works fine, however a pact file isn't generated to record this expectation? When I write a happy path contract scenario (where I'm expecting a status of `200`, this will then generate the pact file. Is there something I'm doing wrong? I have ``` then: assert result instanceof PactVerificationResult.Error` ``` which asserts fine

msc.consults
2019-03-09 13:09
All resolved now, many thanks! ^^

james.carman
2019-03-09 13:43
What was it?

timepasstimepass1234
2019-03-11 12:02
has joined #pact-jvm

timepasstimepass1234
2019-03-11 12:03
Hi All,

timepasstimepass1234
2019-03-11 12:03
My controller call is returning result in DeferredResult format. MockMvcTarget returns the result without waiting for async process. How to add async option to pact through PactDslWithProvider builder in java?

abubics
2019-03-11 22:48
What are you trying to test? The interaction is pretty unclear from that huge payload :slightly_smiling_face:

abubics
2019-03-11 22:49
if your response is meant to have a list of objects, e.g. ```[ {...}, {...}, ... ]``` then you probably want `eachLike`

abubics
2019-03-11 22:50
but also remember that Pact isn't for verifying specific content, it's more fo verifying the shape of the data

pltran875
2019-03-11 23:46
has joined #pact-jvm

pltran875
2019-03-12 00:03
Has anyone used the pact-jvm-provider-gradle before? I am getting Could not find method hasPactsFromPactBroker() when trying to publish to broker on a pactVerify

abubics
2019-03-12 04:14
"Every used before" is maybe not specific enough :wink: I haven't used it in about 9 months

abubics
2019-03-12 04:14
(but it was working then :P)

luca.ippolito
2019-03-12 08:30
has joined #pact-jvm

luca.ippolito
2019-03-12 09:59
Hi there! I've got a question regarding the execution order of provider states, couldn't find anything elsewhere about this. So, let's assume in a contract are the following states configured for a testcase: "providerStates": [ { "name": "service has student", "params": { "id": 1, "firstName": "John", "lastName": "Doe" } }, { "name": "student has grade", "params": { "subject": "Mathematics", "grade": "A" } } ] The expected result by the consumer for this testcase would be "student": { "id": 2, "firstName": "John", "lastName": "Doe", "grades": [ { "subject": "Mathematics", "grade": "A" } ] } When executing this testcase as a provider, I noticed that the execution order of the provider states is reversed, so instead of executing the provider states in this order on the provider side: 1. service has student 2. student has grade The states are getting executed like this: 1. student has grade 2. service has student Can anyone explain me, why the execution order is inverted? Because of that, on the provider side we are implementing something like a "reverse builder pattern" to setup the object that needs to be returned. What would be a better approach on this? I know, a possible answer would be "just use one provider state instead", but I would like to allow multiple consumers to use the same states and they should be able to create their own expected result value, so my key requirement is the usage of multiple paramterized states. Another possible solution would be to tell the consumer that he should invert the order of the provider states on his side, but that does not make that much sense to me. I think, it is more logical to set the provider states like this: .given("service has student", studentParameters).given("student has grade", gradeParameters) instead of setting the states up like this: .given("student has grade", gradeParameters).given("service has student", studentParameters) Thanks in advance for your feedback!

uglyog
2019-03-13 02:20
@luca.ippolito the provider states are keyed by name, so the other would probably be executed based on JVM hash order. But I would recommend to not have your provider states dependent on the order they are executed.

msc.consults
2019-03-13 07:56
@james.carman I was incorrectly using the DSL and not catching the RestClientResponseException that was thrown, its then within the handled exception that I can carry-out my assertions followed by asserting that the PactVerifcationResult is ok >>> James Carman [1:43 PM] What was it?

luca.ippolito
2019-03-13 07:57
@uglyog What do you mean by "keyed by name" I've implemented some states that are only logging their state name to test this, example: @State("A") public void a() { log.debug("A"); } So the following configuration: Verifying a pact between blueadit-fulfillment and blueadit-devices-subscriber-inventory Given A Given B Given C orderTest Results in this execution order: 2019-03-13 08:44:10.355 DEBUG (main) C 2019-03-13 08:44:10.356 DEBUG (main) B 2019-03-13 08:44:10.356 DEBUG (main) A While this configuration: Verifying a pact between blueadit-fulfillment and blueadit-devices-subscriber-inventory Given C Given A Given B orderTest Results in this execution order: 2019-03-13 08:40:17.077 DEBUG (main) B 2019-03-13 08:40:17.078 DEBUG (main) A 2019-03-13 08:40:17.078 DEBUG (main) C I cannot see any keying by name there as you mentioned in your comment earlier. Else I would expect the same order of execution for both tests. Also you mentioned that you wouldn't recommend dependent states. So do you know how i would solve a problem like i described in my first post? Let's say I've got a student object that is expected by the consumer looking like this: { "id": 0, "firstName": "string", "lastName": "string", "grades": [ { "subject": "string", "grade": "string" } ] } Possible that would be a valid usecase for different consumers would be: Example 1: {} Example 2: { "id": 1, "firstName": "John", "lastName": "Doe", "grades": [ { "subject": "Mathematics", "grade": "A" } ] } Example 3: { "id": 2, "firstName": "Johnas", "lastName": "Keller", "grades": [ { "subject": "Mathematics", "grade": "C" }, { "subject": "Geography", "grade": "B" } ] } As far as i know until now, to reduce code duplication and avoid hard coded data, i need multiple states that are using parameters and are dependent to each other, so for each example the states would look something like this (params in brackets would be transmitted as a parameter map and not as part of the name of the state: Example 1: actually no states needed Example 2: "service has student" (params: id = 1, firstName = "John", lastName = "Doe"), "student has grade" (subject = "Mathematics", grade = "A") Example 3: "service has student" (params: id = 2, firstName = "Johnas", lastName = "Keller"), "student has grade" (subject = "Mathematics", grade = "C"), "student has grade" (subject = "Geography", grade = "B") What would be the best approach on this in your oppinion?

james.carman
2019-03-13 11:36
Ahhh, good to know. Thanks for sharing.

alisdaircole
2019-03-13 16:39
has joined #pact-jvm

abubics
2019-03-13 22:53
Not here to help with this specific problem, but you could make your posts easier to digest for people with some formatting :slightly_smiling_face: there's a tiny little tooltip in Slack when you start typing:

luca.ippolito
2019-03-14 07:20
@abubics Thanks, did not know about this

ghandour.jihad
2019-03-14 08:34
has joined #pact-jvm

ghandour.jihad
2019-03-14 11:03
Wrong thread

pltran875
2019-03-14 12:40
Does the pact-jvm-provider-gradle alway expects a running provider for the pactVerify task. I know that starting a provider with stubbing seems to be the most common appropriate. Are there other ways supported like invoking annotated test methods?

luca.ippolito
2019-03-14 13:18
@ghandour.jihad which thread then? I've already been told that this does not belong to #general and was referred to this thread

ghandour.jihad
2019-03-14 13:41
@luca.ippolito, I wrote something here, then edited it by saying wrong thread, I meant "I used the wrong thread" sorry for that :slightly_smiling_face: I reposted my question on the right thread, and now will edit again the message to clarify what I meant

ghandour.jihad
2019-03-14 13:42
apparently I can't double edit a comment. Anyway, it is just that what I previously wrote is on the wrong thread, sorry again

abubics
2019-03-14 23:35
(fyi, you can edit as many times as you like, but there's a time limit)

luca.ippolito
2019-03-15 06:30
@uglyog any input regarding my question?

ghandour.jihad
2019-03-15 13:32
From a consumer test I generated the below json using .stringType since I only care that I have strings and not their actual value: "response": { "status": 200, "headers": { "Content-Type": "application/json;charset=UTF-8" }, "body": [ { "name": "bob", "familyName": "winston" }, { "name": "bob", "familyName": "winston" } ], "matchingRules": { "$.body[0].name": { "match": "type" }, "$.body[0].familyName": { "match": "type" } } } When I place it inside the provider, it is failing due to: Failures: 0) Validating the response content returns a response which has a matching body $.1.name-> Expected 'bob' but received 'Jhon' Apparently PACT is comparing the value and not just the type as indicated in the machingRules Am I missing something? or is there a bug in the matchingRules?

ghandour.jihad
2019-03-15 13:36
Well Apparently there is indeed a bug. in the consumer test, I had .setNumberExamples(2); that should have generated "matchingRules": { "$.body[0].name": { "match": "type" }, "$.body[0].familyName": { "match": "type" }, "$.body[1].name": { "match": "type" }, "$.body[1].familyName": { "match": "type" } } and not just body[0] How can someone report a bug?

ghandour.jihad
2019-03-15 13:57
or it should have added "matchingRules": { "$.body[*].name": { "match": "type" }, "$.body[*].familyName": { "match": "type" } }

uglyog
2019-03-15 22:20
I don?t know why your provider states are executing in that particular order. I assumed it was iterating over a hash map. I still don?t think it is a good idea to have states dependent on each other. There is no guarantee on the order of execution.

luca.ippolito
2019-03-17 08:46
@uglyog how would you design the states than?

uglyog
2019-03-17 20:34
I?d make them to not be dependent on each other. Takes more effort, but makes for much less brittle testing.

dagarwal
2019-03-18 09:51
I was passing multiple data and it was behaving weirdly .So i have reduced the content and its working fine now :slightly_smiling_face:

luca.ippolito
2019-03-18 11:46
@uglyog Can you give me some examples of providerstates and possible parameters you would provide with a state?

sumanthbharan
2019-03-20 08:41
has joined #pact-jvm

sumanthbharan
2019-03-20 09:00
Hi everyone, I want to ask a question related to modifying the request before provider verification. Is it possible to modify the parameter value in the body for post request? The wiki here(https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider-junit#modifying-the-requests-before-they-are-sent-version-323245) provides an option but org.apache.http.HttpRequest allows us to modify the header but not the body. This is my relevant pact information: ```"request": { "method": "POST", "path": "/testApi", "headers": { "Content-Type": "application/json" }, "body": { "fileName": { "s3ObjectKey": "1649a6d0-4aee-11e9-8646-d663bd873d93" } }, "matchingRules": { "body": { "$['fileName'].s3ObjectKey": { "matchers": [ { "match": "regex", "regex": "([a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12})" } ] } } } },``` I would like to modify the s3ObjectKey as it is generated.

paras.vora
2019-03-27 08:30
has joined #pact-jvm

paras.vora
2019-03-27 08:35
@here hello, I have a scenarios where there is an auth token(valid for only 3 mins) required for any request to be addressed.


paras.vora
2019-03-27 08:38
However, I see the auth token is been hardcoded in the code. As I mentioned, the token will expire after 3 mins.

paras.vora
2019-03-27 08:39
Hence, seems this wont be a prominent solution to my case.

paras.vora
2019-03-27 08:39
Could anyone please help in this regard?

paras.vora
2019-03-27 08:45
Also, is there any working sample code repo which would help for using the below code, ```pact { serviceProviders { provider1 { requestFilter = { req -> // Add an authorization header to each request req.addHeader('Authorization', 'OAUTH eyJhbGciOiJSUzI1NiIsImN0eSI6ImFw...') } hasPactWith('consumer1') { pactFile = file('path/to/provider1-consumer1-pact.json') } } } }```

paras.vora
2019-03-27 08:46
As, I am unsure how & where to place it.

abubics
2019-03-27 11:12
There are a few fundamental issues...

abubics
2019-03-27 11:13
1. You don't want chained test cases (doing auth is one, using the same token for other requests is other test cases)

abubics
2019-03-27 11:14
2. Auth isn't the user value feature, it's just a thing you need, as a cross-cutting concern (with indirect user value)

abubics
2019-03-27 11:15
Pact is developing some auth features, but this seems like something you can solve with state

gopinathlangote11
2019-03-27 11:28
@paras.vora https://github.com/gopinath-langote/Pact-JVM-Implementation checkout this :slightly_smiling_face:

gopinathlangote11
2019-03-27 11:28
might help you

paras.vora
2019-03-27 11:31
Thank you @gopinathlangote11 will check & revert.

paras.vora
2019-03-28 04:57
In the repo you shared, could you please help in pointing the reference of bearer token....?

uma.shanker
2019-03-28 15:03
Hi Guys, Getting this error when adding dependencies : `Could not find org.jetbrains.kotlin:kotlin-stdlib-jre8:1.3.21.` Required by: ` project :backend:application > au.com.dius:pact-jvm-consumer-junit_2.11:3.5.0` ` project :backend:application > au.com.dius:pact-jvm-provider-junit_2.11:3.5.0` `project :backend:application > au.com.dius:pact-jvm-consumer-junit_2.11:3.5.0 > au.com.dius:pact-jvm-consumer_2.11:3.5.0` `project :backend:application > au.com.dius:pact-jvm-provider-junit_2.11:3.5.0 > au.com.dius:pact-jvm-provider_2.11:3.5.0` ` project :backend:application > au.com.dius:pact-jvm-consumer-junit_2.11:3.5.0 > au.com.dius:pact-jvm-consumer_2.11:3.5.0 > au.com.dius:pact-jvm-model:3.5.0` `project :backend:application > au.com.dius:pact-jvm-consumer-junit_2.11:3.5.0 > au.com.dius:pact-jvm-consumer_2.11:3.5.0 > au.com.dius:pact-jvm-matchers_2.11:3.5.0`

uma.shanker
2019-03-28 15:04
Please help me on it I am using ` kotlinVersion = '1.3.21'` `springBootVersion = '2.1.3.RELEASE'`

uglyog
2019-03-30 01:45
org.jetbrains.kotlin:kotlin-stdlib-jre8 was dropped with Kotlin 1.3.x. Use a later version of Pact JVM or use Kotlin 1.2.71

uma.shanker
2019-04-01 08:55
Thanks @uglyog but I think I am using the latest version of pact jvm which is 3.5.x. If it is not, do you know what is the latest version of pact jvm? can you please point me there.

uma.shanker
2019-04-01 09:46
Thanks @uglyog by using 3.5.24 fixed the issue. thank you so much.

skirankumars31
2019-04-01 10:44
has joined #pact-jvm

ghandour.jihad
2019-04-04 06:54
Hello fellow jvm Pacters :slightly_smiling_face:, is there a bug in eachKeyLike? In the body response I will have something like the below, where both SERVICE_NAME_PORT and 12345 can change. "ports": { "SERVICE_NAME_PORT": "12345" } I used in the consumer test: .object("ports") .eachKeyLike("SERVICE_NAME_PORT",PactDslJsonRootValue.stringType()) .closeObject() which generated a pact "body": [ { "ports": { "SERVICE_NAME_PORT": "string" }, } ], "matchingRules": { "$.body[0].ports.*": { "match": "type" } } Yet the provider tests are failing with 0) test returns a response which has a matching body $.0.ports -> Expected SERVICE_NAME_PORT='string' but was missing Diff: { - "SERVICE_NAME_PORT": "string" + "MY_SERVICE_NAME_PORT": "10001" } Any idea how can I do it?

uglyog
2019-04-04 08:32
What version of pact-Jvm are you using?

ghandour.jihad
2019-04-04 08:57
<dependency> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-provider-junit_2.12</artifactId> <version>3.6.1</version> </dependency>

ghandour.jihad
2019-04-04 09:13
(tried 3.6.3 now that you asked, and still I have the same problem on provider side)

ghandour.jihad
2019-04-04 09:41
@uglyog I did a dichotomy, The issue is coming from 3.5.22 since it exists there while the issue doesn't exist on 3.5.21

andyharkinsqa
2019-04-04 14:54
has joined #pact-jvm

uglyog
2019-04-04 20:50
Can you raise an issue for this?

ghandour.jihad
2019-04-05 08:09
Done thanks!

paras.vora
2019-04-05 10:31
@matt.fellows Can I get the access to the `Provider` invoked server in my provider test file?

matt.fellows
2019-04-05 11:58
What does this mean, sorry?

matt.fellows
2019-04-05 11:59
What do you want to do?

paras.vora
2019-04-05 12:03
The provider test invokes the provider service, I need to do some manipulations in the invoked running service before the provider test runs.

paras.vora
2019-04-05 12:04
``` package com.appdirect.itg.invoice.template.configuration.contract; import org.junit.Before; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import au.com.dius.pact.provider.junit.Provider; import au.com.dius.pact.provider.junit.State; import au.com.dius.pact.provider.junit.loader.PactBroker; import au.com.dius.pact.provider.junit.target.Target; import au.com.dius.pact.provider.junit.target.TestTarget; import au.com.dius.pact.provider.spring.SpringRestPactRunner; import au.com.dius.pact.provider.spring.target.SpringBootHttpTarget; @RunWith(SpringRestPactRunner.class) @Provider("itg") @PactBroker(failIfNoPactsFound = false) @Category(ContractTest.class) @ContextConfiguration(classes = InvoiceTemplateConfigurationApplication.class) @SpringBootTest( classes = {InvoiceTemplateConfigurationApplication.class,TestJwtConfiguration.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {"spring.profiles.active=test", "spring.main.web-application-type=reactive","spring.main.allow-bean-definition-overriding=true"} ) public class ProviderTest { @TestTarget public final Target target = new SpringBootHttpTarget(); @Before public void setup() { System.out.println(); } @State("Return template Tokens as json") public void getTemplateTokens() { } @State("Validate the Json") public void validateTemplateJson() { } @State("Return active template Json for Invoice in Base64 encoded") public void getActiveTemplateJsonForInvoice() { } } ```

paras.vora
2019-04-05 12:06
Need to do some manipulation with the invoked server in the setup block.

matt.fellows
2019-04-05 20:03
@uglyog?

matt.fellows
2019-04-05 20:05
I'd have thought given you're in the spring context you can do whatever you need using spring framework

uglyog
2019-04-07 23:27
That what the provider states are for. You can inject any spring bean into the test

sam
2019-04-08 21:24
Looking for some advice... I'm creating a Pact for an endpoint that is a POST with form urlencoded params. Is there a way to generally specify the params expected (ex: a param called "foo" that's a string) like I can do JSON response body?

sam
2019-04-08 21:25
Right now I have something like this `body("requestId=1234&start=1262300400", ContentType.APPLICATION_FORM_URLENCODED)`

sam
2019-04-08 21:26
but I was hoping to be more general with the values passed in, and just declare the param name and type

uglyog
2019-04-08 23:34
No, there is no current support for specifying individual parameters. But it should be easy to implement.

nschmuter
2019-04-09 13:11
has joined #pact-jvm

ghandour.jihad
2019-04-10 07:14
Please let me know if I should raise an issue: I am using <dependency> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-consumer-junit_2.12</artifactId> <version>3.5.11</version> </dependency> In my consumer tests I use: MockProviderConfig config = MockProviderConfig.createDefault(); PactVerificationResult pactVerificationResult = runConsumerTest(pact, config, mockServer -> { List<URI> response = new ProviderClient(new ProviderConfig(mockServer.getUrl())); assertEquals(1,response.size()); }); assertEquals(PactVerificationResult.Ok.INSTANCE, pactVerificationResult); When this fails, the output is polluted: java.lang.AssertionError: Expected :au.com.dius.pact.consumer.PactVerificationResult$Ok@4044fb95> but was:<Error(error=java.lang.AssertionError: expected:<1 Actual :2>, mockServerState=au.com.dius.pact.consumer.PactVerificationResult$Ok@4044fb95)

uglyog
2019-04-10 09:15
@ghandour.jihad why are you using version 3.5.11?

uglyog
2019-04-10 09:17
But I guess your assertion is failing: `assertEquals(1,response.size());` -> `AssertionError: expected:<1 Actual :2`

uglyog
2019-04-10 09:18
I.e., your response has size 2, not 1

ghandour.jihad
2019-04-10 09:58
(I upgraded to 3.6.3 now and it aswell has the same problem)

ghandour.jihad
2019-04-10 09:59
indeed this is the assertion that is failing, I intended to make it fail, so that I see how will the result be outputed in the Intellij console

ghandour.jihad
2019-04-10 10:00
problem is I get java.lang.AssertionError: Expected :au.com.dius.pact.consumer.PactVerificationResult$Ok@2ceb80a1> but was:<Error(error=java.lang.AssertionError: expected:<1 Actual :2>, mockServerState=au.com.dius.pact.consumer.PactVerificationResult$Ok@2ceb80a1) While I was expecting for something more neat like java.lang.AssertionError: Expected :1 Actual :2

ghandour.jihad
2019-04-12 16:04
Kind reminder on this :slightly_smiling_face: @uglyog, do you think I should open an issue?

uglyog
2019-04-13 03:56
No, it is not an issue. It is working as intended. The assertion error is getting caught by the pact framework and being wrapped in a Error and then re-thrown.

jadedevin13
2019-04-19 09:08
has joined #pact-jvm

alexei
2019-04-23 09:59
has joined #pact-jvm

alexei
2019-04-23 10:02
Hi, where do I put consumer version with gradle publishing pact on pact broker? I haven?t found it in documentation yet. gradle project.version is being used, but there is also a case with one build uploading pacts for different consumers, what are the ways to differentiate?

alexei
2019-04-23 10:06
I also missing documenation about how to version the provider for the broker verfication (Junit5, gradle)?.

alexei
2019-04-23 11:11
Update. Found this one: For pacts that are loaded from a Pact Broker, the results of running the verification can be published back to the broker against the URL for the pact. You will be able to see the result on the Pact Broker home screen. You need to set the version of the provider that is verified using the **pact.provider.version system property**. To enable publishing of results, set the property pact.verifier.publishResults to true [version 3.5.18+].

mvpatel1982
2019-04-24 06:47
has joined #pact-jvm

alexei
2019-04-24 13:53
it is just version like in> ``` pact { publish { pactDirectory = 'build/pact-files' // defaults to $buildDir/pacts pactBrokerUrl = url pactBrokerUsername = pactBrokerUser pactBrokerPassword = pactBrokerPwd version="${project.version}-${getGitHashForLastCommit()}" } ```` but possibly not mentioned in README

uglyog
2019-04-25 04:20
It uses the version property from the project by default, which can be overwritten as you have done

alexei
2019-04-25 07:58
Another question. @uglyog Suppose i have the same request which delivers different responses depending on state. Example: State=normal /find/book/1 returns json response State=empty db /find/book/1 returns 404 How do I test it in consumer? In this example my mock server returns as if in "normal", didn't find a way to switch between states on consumer side.

uglyog
2019-04-25 08:00
The consumer test would have 2 different test cases which define the expected response and the provider state

alexei
2019-04-25 08:00
Do you have a link to example?

alexei
2019-04-25 08:01
https://github.com/DiUS/pact-jvm/blob/master/pact-jvm-consumer-junit/README.md#using-the-base-consumerpacttest Here are two states with just one test, unclear how to define states in tests...

uglyog
2019-04-25 08:02
No, you use one state per test. The two interactions then go into the same pact file

alexei
2019-04-25 08:04
So it is probably doable if there are two different paths for each test. But if the path is the same?

alexei
2019-04-25 08:04
(Using junit5)

uglyog
2019-04-25 08:05
The path doesn't matter. Each test gets it's own mock server which knows how to behave based on the expected interactions.

alexei
2019-04-25 08:07
``` @Test void test(MockServer mockServer) throws IOException { HttpResponse httpResponse = Request.Get(mockServer.getUrl() + "/articles.json").execute().returnResponse(); assertThat(httpResponse.getStatusLine().getStatusCode(), is(equalTo(200))); }```

alexei
2019-04-25 08:08
How do I configure the right state for the mock? The pact find is okay, but I cant find the way to test the second state for consumer.

alexei
2019-04-25 08:10
Let's imagine, the same url/articles.json return 200 (as above) or 404.

uglyog
2019-04-25 08:12
The states are not used on the consumer test. The mock server uses the defined response for the test. So you setup one pact fragment with a 200 response and provider state "article exists" and one with 404 response and "article does not exist". Then you have two tests, one which uses the first fragment and the other the second.

alexei
2019-04-25 08:13
But it doesn't work if the "request" part of both fragments is the same)

alexei
2019-04-25 08:14
It works if first fragment /article/1, the second fragment /article/1984

alexei
2019-04-25 08:15
But not for the same /article request, because mock always answers with one and the same response

uglyog
2019-04-25 08:15
the first test will get a mock server that returns a 200 response from `/articles.json` and the second test will get a new mock server that returns a 404 to that URL

alexei
2019-04-25 08:16
As if mockServer.useState(String ...) is missing

uglyog
2019-04-25 08:16
Might be easier if I just write the test for you :smile:

alexei
2019-04-25 08:20
``` @Test void test(MockServer mockServer) throws IOException { HttpResponse httpResponse = Request.Get(mockServer.getUrl() + "/articles.json").execute().returnResponse(); assertThat(httpResponse.getStatusLine().getStatusCode(), is(equalTo(404))); }``` Just like this??


alexei
2019-04-25 10:11
It must be properly bound some how, it cannot work this way without binding test to fragement

alexei
2019-04-25 10:15
Thanks! I solved it the same way on the plane)) I had the interaction in one method, then there is no way to differentiate. That is from README example

pltran875
2019-04-26 09:16
Anyone knows if there is a Gradle equivalent of the can-i-deploy functionality?

gopinathlangote11
2019-04-26 12:10
Here, anyone using pact maven plugin with S3 to store contract files? As currently `pact-jvm-provider-maven` do not support AWS S3 to store/retrieve the contracts files? @maintainer any plans to support the same? If you feel it is useful, I don?t mind submitting PR :slightly_smiling_face:

uglyog
2019-04-28 05:55
There is support for loading pacts from S3. Publishing would just mean copying the pact files, so there is no need to create a pact plugin for that. Just use the AWS cli.

gopinathlangote11
2019-04-28 11:30
@uglyog Thanks for the response. About loading pact from s3, is there support in `pact-jvm-provider-maven`, I was not able to find the same. Could you share the link to document if I am missing something

richard.jones
2019-04-29 00:07
has joined #pact-jvm

uglyog
2019-04-29 00:58
Just checked, and it only works for 3.5.x and not for the maven plugin. It works by using an S3 URL S3://...

richard.jones
2019-04-29 04:10
Hi folks, I?ve just confirmed that the latest pact-jvm (3.6.5) generates a `"min": 0` when `.arrayEachLike()` is used, but believe it should be defaulting to `"min": 1` given that?s the recommendation as detailed https://docs.pact.io/faq#why-is-there-no-support-for-specifying-optional-attributes (the ruby and python implementations treat an EachLike minimum of 0 as an error).

uglyog
2019-04-29 08:47
That's correct. `arrayEachLike` generates `"min": 0` while `minArrayLike(n)` generates `"min": n`

gopinathlangote11
2019-04-29 09:09
How to handle auth for S3 url?

gopinathlangote11
2019-04-29 09:10
& Can we add native support for maven plugin

uglyog
2019-04-29 09:11
Please raise an issue or create a PR for it at https://github.com/DiUS/pact-jvm

gopinathlangote11
2019-04-29 09:21
@uglyog I have already created issue for the same https://github.com/DiUS/pact-jvm/issues/875

gopinathlangote11
2019-04-29 09:21
I can propose more details there!

jonathan.ruckwood
2019-04-29 11:52
has joined #pact-jvm

richard.jones
2019-04-29 22:20
@uglyog I believe it should generate a default min of 0, otherwise the generated pacts are not valid (certainly they break the broker, which only handles the valid case of min > 0)

uglyog
2019-04-29 22:23
Then that issue is with the broker. There is nothing invalid about having min=0, it is a valid use case.

richard.jones
2019-04-29 22:24
I believe you and @bethskurrie need to discuss that further then :slightly_smiling_face:

richard.jones
2019-04-29 22:24
Per https://docs.pact.io/faq#why-is-there-no-support-for-specifying-optional-attributes ?The same goes for specifying an array with length 0 or more. If all your provider verification data returned 0 length arrays, all your verification tests would pass without you ever having validated the contents of the array. This is why you can only specify an array with minimum length 1 OR a zero length array.?

uglyog
2019-04-30 08:05
@bethskurrie what have you done?

christophe
2019-05-01 16:08
has joined #pact-jvm

noel.yap_slack.pact.i
2019-05-08 16:43
has joined #pact-jvm

james.hattersley-dyke
2019-05-24 07:34
has joined #pact-jvm

james.hattersley-dyke
2019-05-24 07:36
Hi, can anyone point me at some examples of converting a PactMessage class to a JSON string? I can generate the Pact, but when I try invoke my message handler, I get validation / deserialisation errors - We're using a message handler that just accepts the string of the raw message

james.hattersley-dyke
2019-05-24 07:41
``` messageStream.run { Message message -> def json = JsonOutput.toJson(message.contentsAsBytes()) productSubscriber.handleEvent(json) ``` assertion not shown here, but i've tried multiple variations on this, the `handle` method takes a string parameter of the actual message

james.hattersley-dyke
2019-05-24 07:53
it's ok I got this... wasn't clear from the docs, that for a java n00b like me you can just do `new String(message.contentsAsBytes())`

james.hattersley-dyke
2019-05-24 07:53
might be worth throwing that on at the end :slightly_smiling_face:

uglyog
2019-05-24 08:56
You can also do something like `message.getContents().valueAsString()`

james.hattersley-dyke
2019-05-24 09:27
ah right, that's good to know. I'm just getting to grips with Java / Groovy et al

james.hattersley-dyke
2019-05-24 13:56
Anyone know what to do with this? ``` could not create Vfs.Dir from url. ignoring the exception and continuing org.reflections.ReflectionsException: could not create Vfs.Dir from url, no matching UrlType was found [file:/C:/Code/product-command/build/classes/groovy/main] either use fromURL(final URL url, final List<UrlType> urlTypes) or use the static setDefaultURLTypes(final List<UrlType> urlTypes) or addDefaultURLTypes(UrlType urlType) with your specialized UrlType. ```

james.hattersley-dyke
2019-05-24 14:07
``` serviceProviders { 'selling-product-command' { verificationType = 'ANNOTATED_METHOD' packagesToScan = ['com.companyname.sellingproductcommand.*'] hasPactsFromPactBroker(brokerUrl, authentication: ['Bearer', brokerToken]) } } ```

james.hattersley-dyke
2019-05-24 14:46
This is when trying to use the message verification in the pact-jvm-provider-gradle, been stuck on it a while now, not sure there's much I can affect

diandra
2019-05-28 00:21
has joined #pact-jvm

simone.dicola
2019-05-28 08:33
has joined #pact-jvm

simone.dicola
2019-05-28 08:33
Morning all

simone.dicola
2019-05-28 08:34
I have created the following test

simone.dicola
2019-05-28 08:35
But when I run gradlew test

simone.dicola
2019-05-28 08:35
I am not able to generate the pact

simone.dicola
2019-05-28 08:35
Sure I am missing something :slightly_smiling_face:

simone.dicola
2019-05-28 08:35
for instance runConsumerTest

simone.dicola
2019-05-28 08:35
anyone can shed some light ?

simone.dicola
2019-05-28 08:48
import static au.com.dius.pact.consumer.ConsumerPactRunnerKt.runConsumerTest;

simone.dicola
2019-05-28 09:14
is there anyone here?

abubics
2019-05-28 23:41
It's morning here now :slightly_smiling_face:


abubics
2019-05-28 23:45
but it depends what style of testing you want to work with :slightly_smiling_face:

abubics
2019-05-28 23:46
I think, if you set up the provider manually (as in your example), and build a pact object (as you have, via `.toPact()`), you will need to manually call `runConsumerTest(pact, config, (mockServer, context) -> { ... })`


simone.dicola
2019-05-30 10:09
Thanks @abubics

russell.blandamer
2019-05-30 10:44
has joined #pact-jvm

simone.dicola
2019-05-30 12:11
sorted :slightly_smiling_face:

antonello
2019-06-03 22:42
Hi! It?s me again. Is it possible to split provider verification tests for a single provider into different classes (for example to have a separate class for each endpoint) without having to resort to using @PactFilter annotations? @PactFilter works a treat, but it also means that when a consumer adds a new interaction to an existing pact, given that the provider is filtering, the verification succeeds even if the new interaction hasn?t been verified.

richard.jones
2019-06-03 23:03
Hi folks, I just wanted to note that a lot of the links (like pact-jvm-consumer-specs2, pact-jvm-consumer-junit, ?) on https://github.com/DiUS/pact-jvm are broken. I?m trying to find docs on the JVM API :slightly_smiling_face: (specifically, how is tagging of pacts done? if the JVM impl doesn?t submit pacts to the broker, then ignore my question :smile: )

uglyog
2019-06-04 00:14
@richard.jones use the v3.6.x branch until I can correct the links.

richard.jones
2019-06-04 00:26
okie, thanks!

uglyog
2019-06-04 00:39
There is no current way to only validate a subset of the interactions without using @PactFilter. Can you raise an issue for this at the github project?

antonello
2019-06-04 07:04
Thank @uglyog. I don?t really want to validate a subset of interactions though. I would either like to have the ability of sharing various @State across more than one class without having to using @PactFilter or the ability to know if any interactions defined in our pacts haven?t been verified.

antonello
2019-06-04 07:30
I thought this (https://github.com/DiUS/pact-jvm/issues/522) would address our issue, but we?re using the SpringRestPactRunner.

alessio.paciello
2019-06-04 08:44
has joined #pact-jvm

ben
2019-06-04 11:14
has joined #pact-jvm

rob.clarken
2019-06-04 22:47
has joined #pact-jvm

antonello
2019-06-05 06:23
@uglyog @bethskurrie Reading your comments on the issue above, the expected behaviour should be that if you use @PactFilter and only verify a subset of interactions in a pact, the verification should fail if all defined interactions are not verified. Am I understanding it correctly? And would that be the case for the SpringRestPactRunner?

uglyog
2019-06-05 06:27
At the moment, it won't fail the build (it generates a test per interaction), but will not publish the verification result back to the broker unless all the interactions where verified

antonello
2019-06-05 06:35
Gotcha. We thought we were seeing something different but it?s possible we just go confused by the pact broker indicating the pact has been verified, but it?s possible that it was verified by a feature branch. We will retest what we thought we saw, but I?m sure it behaves as expected (as in as you say above).

alessio.paciello
2019-06-05 09:15
Hello! Any hint on enabling DEBUG logging level on `pact-jvm-provider-junit` ?

uglyog
2019-06-05 09:20
Use any SLF4J logging library. logback is one such. It will enable debug level by default

alessio.paciello
2019-06-05 10:14
thanks! Actually the problem was that `logback-test.xml` wasn't picked up

antonello
2019-06-05 16:57
@uglyog Sadly we have been able to demonstrate the problem. I?ve raised an issue: https://github.com/DiUS/pact-jvm/issues/889 I am not providing a working example because it?s incredibly easy to reproduce, but let me know if you need any further clarification.

antonello
2019-06-06 08:15
By the way, any idea of when v4 will be released? Just wondering what we should target if we wanted to fix the issue above, or whether we should aim to fix it both.

uglyog
2019-06-06 08:16
Lots of re-factoring happening. The beta versions are available. Once it is stable the beta will be dropped

uglyog
2019-06-06 08:17
Fix it in master. If needed we can backport it to 3.6.x

steveland
2019-06-06 15:11
has joined #pact-jvm

antonello
2019-06-06 17:57
@uglyog We turned it around quite quickly thanks to @alessio.paciello! :-) If you?re ok with it, I think we may want it on 3.6.x. Also, we were wondering if we should also fail the test run.

hboddupalli
2019-06-07 21:34
has joined #pact-jvm

sgleadow
2019-06-10 23:09
@sgleadow has left the channel

iamtarasshevchenko
2019-06-12 11:23
has joined #pact-jvm

thomas.scheuchzer2
2019-06-12 13:23
has joined #pact-jvm

thomas.scheuchzer2
2019-06-12 13:25
Hi. Does anybody mind if we migrate some groovy classes to kotlin on the v4 branch?

uglyog
2019-06-12 22:46
That was the whole point of the V4 refactor :smile: But it is now merged to master

gerwin.vaatstra
2019-06-13 07:09
has joined #pact-jvm

vivek.125
2019-06-13 19:46
has joined #pact-jvm

vivek.125
2019-06-13 19:46
hi, how can i get the request reponse logs when running a provider?

vivek.125
2019-06-13 20:00
@uglyog

uglyog
2019-06-13 22:13
Set you log level to debug

cjadav
2019-06-14 05:42
has joined #pact-jvm

cjadav
2019-06-14 12:22
Hi i have this body in consumer tests ```PactDslJsonBody response = new PactDslJsonBody() //.numberType("id") //.id("id") .id() //.numberValue("id", 1) .stringType("clientId") .stringType("clientSecret") .stringValue("applicationName","flex-publish-service") .stringValue("description","abc")``` after creating json it is giving 500 errors for post call, i am facing problem with id. if i use .id("id",10L) it worked but i want id to be random and will be ignored in provider verification

gerwin.vaatstra
2019-06-17 07:32
I had an issue (resolved it by specifying the contract differently) but I wonder if it is a bug. I had this contract that resulted in the matchingrule in the body of "$.payload$.bestandsid" (double $): PactDslJsonBody body = new PactDslJsonBody(); body.object("headers") .stringValue("bestandstype", "dpc") .stringValue("Content-Type", "application/json") .closeObject(); payload = new PactDslJsonBody(); payload.stringValue("bestandstype", "dpc") .stringValue("bestandsid", EXAMPLE_DPC_FILE_NAME) .closeObject(); body.object("payload", payload); The issue here is that when I use a PactDslJsonBody as DslPart in 'body.object("payload", payload)', I get the extra $ Second thing I noticed is that the error message isn't mentioning the extra $: 0) A message notifying a newly available foo file generates a message which has a matching body $.payload.bestandsid -> Expected 'string' but received '20190219_foo_20190124.txt'

drambhia
2019-06-17 15:27
has joined #pact-jvm

james.hattersley-dyke
2019-06-17 15:27
Hi, just wondering if anyone has any advice really... I've got a provider that spits out a large amount of json, I'm feeling lazy and can't be doing with specifying each field (some of the information is repeated), however my message consumer only consumes fully formed messages... is there a way to 'reuse' the message generation code? In my consumer tests I'm instanciating a message subscriber and pushing the generated JSON through that class... ``` given: "Product Command produces the following message" def messageStream = new PactMessageBuilder().call { serviceConsumer 'web-cmd' hasPactWith 'product-command' given 'the service can accept incoming messages' expectsToReceive 'a fully formed product message' withContent { .... } when: "a message is received" messageStream.run { def s = new String(it.contentsAsBytes()) productSubscriber.handleEvent(s) } then: "the valid message is persisted to the database" 1 * ProductDAO.save(_ as DynamoDB) >> { it.id == '12344323' } ``` Am I doing this right? Is there any easier way?

anddreiu
2019-06-17 15:51
has joined #pact-jvm

uglyog
2019-06-17 23:14
@james.hattersley-dyke not sure what you asking. Do you want to use the message provider code to generate the message for the consumer test?

abubics
2019-06-18 00:51
Hello! is `4.0.0-beta.1` a good version to use? Or is it not-so-stable?

uglyog
2019-06-18 00:53
It is usable in the sense that it should work. It is unstable in the sense that there is a big re-factor going on, so all the classes and method signatures may change before 4.0.0

uglyog
2019-06-18 00:54
That looks like an error. What version are you using?

abubics
2019-06-18 00:56
I see. I think I'll go with 3.6.x then :ok_hand:

abubics
2019-06-18 01:02
(oh, and thanks :pray: )

agarwalatrisha1212
2019-06-18 03:18
has joined #pact-jvm

abubics
2019-06-18 06:27
for JVM providers, is there any recommendation or rationale around choosing to verify with gradle vs junit? or just personal preference?

uglyog
2019-06-18 06:30
With JUnit you can have more focused tests, and can mock out collaborators that aren't important

uglyog
2019-06-18 06:31
For instance a service that calls out to another service

abubics
2019-06-18 06:32
right . . . I do that with the gradle verify anyway . . . :thinking_face:

abubics
2019-06-18 06:32
I mean, I've never used the junit verify, so I was wondering how the experience is :slightly_smiling_face:

uglyog
2019-06-18 06:33
Apart from the JUnit bit, I prefer it

abubics
2019-06-18 06:34
welp, I'm in a kotlin codebase with Spek set up (non-junit) so I suppose I have fewer choices :upside_down_face:

uglyog
2019-06-18 06:36
I've done it with Spock as well, just required more test code to be written when the JUnit has annotations to do a lot of that

cjadav
2019-06-18 06:47
Hi Guys, any resolution for this?

uglyog
2019-06-18 06:51
What error do you get?

cjadav
2019-06-18 06:55
```===> Received request: Request { method: "POST", path: "/api/authentication/applications", query: None, headers: Some({"Connection": "keep-alive", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36", "X-App-Registration-Key": "Ld61vMw2jKLBNClekKCkSSshETpX0pUl4S0YpJwPvWBpO4sB", "Cache-Control": "no-cache", "Host": "localhost:18101", "Accept": "*/*", "Content-Type": "application/json", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-IN,en;q=0.9,hi-IN;q=0.8,hi;q=0.7,en-GB;q=0.6,en-US;q=0.5", "Content-Length": "71", "Postman-Token": "d4556f1d-12a8-c22c-e577-f8ce74ebb613", "Origin": ""}), body: Present([123, 10, 32, 32, 34, 97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 78, 97, 109, 101, 34, 58, 32, 34, 102, 108, 101, 120, 45, 112, 117, 98, 108, 105, 115, 104, 45, 115, 101, 114, 118, 105, 99, 101, 34, 44, 10, 32, 32, 34, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 34, 58, 32, 34, 97, 98, 99, 34, 10, 125]), matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } } 06:54:23 [INFO] body: '{ "applicationName": "ftest, "description": "abc" }' 06:54:23 [INFO] comparing to expected request: Request { method: "POST", path: "/api/authentication/applications", query: None, headers: Some({"X-App-Registration-Key": "Ld61vMw2jKLBNClekKCkSSshETpX0pUl4S0YpJwPvWBpO4sB", "Content-Type": "application/json"}), body: Present([123, 34, 97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 78, 97, 109, 101, 34, 58, 34, 102, 108, 101, 120, 45, 112, 117, 98, 108, 105, 115, 104, 45, 115, 101, 114, 118, 105, 99, 101, 34, 44, 34, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 34, 58, 34, 115, 116, 114, 105, 110, 103, 34, 125]), matching_rules: MatchingRules { rules: {"body": Category { name: "body", rules: {"$.description": RuleList { rules: [Type], rule_logic: And }} }} }, generators: Generators { categories: {BODY: {"$.description": RandomString(20)}} } } token = Root body_cursor = Object({"applicationName": String("flex-publish-service"), "clientId": String("string"), "clientSecret": String("string"), "description": String("abc"), "id": Number(1234567890)}) token = Field("id") body_cursor = Object({"applicationName": String("abc"), "clientId": String("string"), "clientSecret": String("string"), "description": String("abc"), "id": Number(1234567890)}) thread '<unnamed>' panicked at 'Rng.gen_range called with low >= high', /home/ronald/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.4.2/src/lib.rs:519:9 note: Run with `RUST_BACKTRACE=1` for a backtrace.```

uglyog
2019-06-18 06:58
> `thread '<unnamed>' panicked at 'Rng.gen_range called with low >= high'`

uglyog
2019-06-18 07:00
Looks like the verification panicked, can you raise on issue at https://github.com/pact-foundation/pact-reference



gerwin.vaatstra
2019-06-18 08:15
At the consumer I use pact-jvm-consumer-junit_2.12 - Version 3.6.2 pact-jvm-consumer-java8_2.12 - Version 3.6.2 I believe I also tried 3.6.7 earlier but also had the issue there


james.hattersley-dyke
2019-06-18 08:30
Hi, I'm saying is there a way to reuse some of the message generation code? And if I'm doing it right asserting that the generated message can still be processed?

james.hattersley-dyke
2019-06-18 10:19
I suppose I could not assert the generated message is handled correctly and just use it to generate the contract? That feels a little risky though

james.hattersley-dyke
2019-06-18 10:34
do you write verbose tests or just enough to generate a contract?

james.hattersley-dyke
2019-06-18 10:36
anyone else want to weigh in on this thread?

gerwin.vaatstra
2019-06-18 10:40
Not really. If you have a lot of JSON and your consumer needs it all, I would say it pays to do the effort. You could also wonder why your consumer needs it all of course. I would go for 1 contract + captures JSONs for the other scenario's and use them on your service

gerwin.vaatstra
2019-06-18 10:41
And if you go the way of "let's generate" then you actually say "whatever it generates is what I expect"

james.hattersley-dyke
2019-06-18 11:10
cool, I was thinking of going all out an generating the entire message then scaling back as we understand more of what's mandatory data. Right now, everything is....

gerwin.vaatstra
2019-06-18 12:21
Instead of scaling down, start with what you need because then you end up with the correct contract instead of checking more than needed

james.hattersley-dyke
2019-06-18 13:46
does anyone know if it's possible to generate matchers for this JSON ``` "standards": { "STANDARD_NAME_2": ["STANDARD_VALUE_2", "STANDARD_VALUE_1"], "STANDARD_NAME_1": ["STANDARD_VALUE_1"] }, ```

james.hattersley-dyke
2019-06-18 13:51
answered my own question - just incase you're interested ``` standards { keyLike 'STANDARD_NAME', eachLike(2, string('STANDARD_VALUE')) } ```

uglyog
2019-06-18 23:49
Looks like a defect. Can you raise an issue for it?

abubics
2019-06-19 00:38
howdy, just setting up a gradle verify, following instructions on https://github.com/DiUS/pact-jvm/tree/master/provider/pact-jvm-provider-gradle#using-a-state-change-url, but getting an unexpected error: ``` > Cannot cast object 'UrlSource(url=http://localhost:8080/pact-state-change, pact=null)' with class 'au.com.dius.pact.model.UrlSource' to class 'java.net.URL' ``` My gradle file looks like ``` pact { serviceProviders { 'app-api' { startProviderTask = startProvider terminateProviderTask = stopProvider hasPactWith('app-ui') { pactSource = file('pacts/app-ui-app-api.json') stateChangeUrl = url('http://localhost:8080/pact-state-change') } } } } ``` Any ideas?

uglyog
2019-06-19 00:38
Oh, damn

uglyog
2019-06-19 00:39
Issue please

abubics
2019-06-19 00:39
oh no

abubics
2019-06-19 00:41
Is there an issue template?


abubics
2019-06-19 00:49
there you go :slightly_smiling_face: cheers~*

abubics
2019-06-19 00:49
lmk if you need more detail, of course

abubics
2019-06-19 01:45
another problem I'm (surprisingly) having . . . most of the time, Pact is failing to hit my provider instance: ``` Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused) ``` but when I `curl` it manually, it's giving the expected responses. The log output shows that it's waited for the provider to finish starting up (using `com.wiredforcode.gradle.spawn.SpawnProcessTask`). I've never seen this before, just wondering if anyone else has. And it has worked a couple of times out of >20 attempts, hinting at a race condition maybe?

uglyog
2019-06-19 01:46
Is it a springboot app?

uglyog
2019-06-19 01:48
I remember the spawn task can wait for some log output to appear. It seems like a race condition that the spawn task has returned because the process is running, but the socket may not have been opened yet

abubics
2019-06-19 01:52
it's a ktor app, and the output indicates that it's really ready, although that could be inaccurate ``` 2019-06-19 11:41:12.659 [main] INFO Application - Responding at http://0.0.0.0:8080 2019-06-19 11:41:12.660 [main] TRACE Application - Application started: io.ktor.application.Application@a68df9 java -jar /Users/.../app-api/build/libs/app-api-0.0.1-SNAPSHOT.jar is ready. ```

abubics
2019-06-19 01:53
I'll check the docs for `SpawnProcessTask` to see if I can delay it after finding the `ready` line

abubics
2019-06-19 02:52
settling for ``` startProvider.doLast { Thread.sleep(100) } ``` but sad about it :cry:


abubics
2019-06-19 07:12
Found the fix, but leaving the issue open until the docs are fixed :slightly_smiling_face:

vetisanvasile
2019-06-19 07:36
has joined #pact-jvm

vetisanvasile
2019-06-19 07:44
Hello guys, I tried to setup logging for pact tests (pact-jvm-provider) with logback and everything seems to work ok. But when I try to use log4j I don't see any info realted to pact classes e.g DEBUG a.c.d.p.p.j.loader.PactBrokerLoader, DEBUG a.c.d.pact.matchers.MatcherExecutor but I see a lot of http logging. Is there incompatibility between pact-jvm and log4j?

uglyog
2019-06-19 07:45
Pact-JVM uses SLF4J. If you want to use log4j, you need to also use a SL4FJ adapter for log4j

james.reynolds
2019-06-19 15:06
has joined #pact-jvm

james.carman
2019-06-19 16:48
We tried upgrading to pact-jvm 3.6.8 and we started getting: ``` groovy.lang.MissingMethodException: No signature of method: java.math.BigDecimal.toInt() is applicable for argument types: () values: [] Possible solutions: print(java.io.PrintWriter), print(java.lang.Object), toLong(), round(), trunc(), round(java.math.MathContext) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:70) at org.codehaus.groovy.vmplugin.v7.IndyGuardsFiltersAndSignatures.unwrap(IndyGuardsFiltersAndSignatures.java:175) at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:234) at au.com.dius.pact.model.Response$_fromMap_closure1.doCall(Response.groovy:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:263) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1041) ... ```

james.carman
2019-06-19 16:51
We are a Spring Boot project and Spring Boot is pinning (via dependencyManagement) Groovy to 2.5.7.

james.carman
2019-06-19 16:56
Looks like pact-jvm uses 2.5.6 in its dependencies, so that shouldn?t be an issue

james.carman
2019-06-19 18:41
Same! :slightly_smiling_face:

james.reynolds
2019-06-19 20:02
Hello! I?m working on setting up my first Pact test in a springboot app. I?m using v`4.0.0-beta.1` and modeling my work after the example here: https://github.com/DiUS/pact-jvm/tree/master/consumer/pact-jvm-consumer-junit I noticed the `ConsumerClient` class isn?t found in the jar. I assume it?s the same that?s used in this test too: https://github.com/DiUS/pact-jvm/blob/master/consumer/pact-jvm-consumer-junit/src/test/java/au/com/dius/pact/consumer/pactproviderrule/PactProviderTest.java#L7 Am I following the wrong example for a JDK 11/Pact 4.0 setup?

uglyog
2019-06-19 23:03
`ConsumerClient` is just an example class and is in the test classpath, you should be using your own classes instead.

oswald.quek
2019-06-21 11:46
has joined #pact-jvm

codrut.gusoi
2019-06-21 13:54
has joined #pact-jvm

shefeeque85
2019-06-22 18:55
has joined #pact-jvm

mui_ume
2019-06-23 09:34
has joined #pact-jvm

jemmawells
2019-06-25 11:46
has joined #pact-jvm

jemmawells
2019-06-25 11:59
Hiya, looking for some guidance! We are currently writing some Providers side tests to verify a Pact File that we have successfully pushed to our Pact Broker. We're currently having issues with basic authentication when trying to access the Pact Broker during the test. We know our username and password are correct - they work without issue in a GET request and a curl. We're just not able to successfully authenticate using the annotations. We're using J Unit 5, and our @PactBroker annotation looks like the above

jemmawells
2019-06-25 11:59
Are there any known issues around this currently?

jemmawells
2019-06-25 12:00
Otherwise, any suggestions on things to try would be greatly received!

carolyn.biggar
2019-06-25 12:04
has joined #pact-jvm

james.carman
2019-06-25 12:15
What?s the error?

carolyn.biggar
2019-06-25 12:40
We're being redirected to our SSO webpage ie getting back html instead of the PACT broker json response. We've just used Charles to intercept what's being sent when we run the test and can see that no Authorization is being set. If you use Bearer on the other hand, you _can_ see the Autherization being set: ```@PactBroker(host = "http://our-broker.net", scheme = "https", port = "443", authentication = PactBrokerAuth(scheme = "Basic", username = "my-bearer-token", password = ""))``` (unfortuately we don't have a bearer token!) This seems to the last comment on this issue, https://github.com/DiUS/pact-jvm/issues/881#issuecomment-494286204 where the commenter mentions that basic auth no longer works - is that a known thing?

alessandrobuggin
2019-06-25 14:40
has joined #pact-jvm

james.hattersley-dyke
2019-06-25 14:41
hi, is there a way to prevent the pact gradle plugin pinging the broker on build? Our broker is locked down heavily right now by IP's in a security group - it means each dev is having to add their IP to the group... or they cannot build locally.... is there a way around this?

james.hattersley-dyke
2019-06-25 15:00
I'm guessing the above ^ relates to this: > NOTE: Currently the pacts are fetched from the broker during the configuration phase of the build. This means that if the broker is not available, you will not be able to run any Gradle tasks. This should be fixed in a forth coming release.

james.hattersley-dyke
2019-06-25 15:01
has this been addressed in v4.x?

cjadav
2019-06-28 13:34
i have ```return builder .given("There is a request to get details of a Job") .uponReceiving("Returns details of the not authorised user " + NOT_AUTHORISED_USER_ID) .headers(headers) .matchPath("/api/filter/[0-9]+") .body(body) .method("POST") .willRespondWith() .status(200) .headers(headers) .body("[]").toPact();``` .matchPath method which creates path like `"path": "/api/filter/13"` but when we run provider verification it tries to do post call of `"path": "/api/filter/13"` and failing as 13 is not available. question is how can we do matchers at provider side to ignore that particular id

uglyog
2019-06-29 01:22
what are you using on the provider side?

uglyog
2019-06-29 01:25
But you should use provider states to setup the correct data so that ID is valid. You can also use `matchPath(String pathRegex, String path)` to use a particular ID

cjadav
2019-07-01 05:48
We are using below code at provider side ```@RunWith(PactRunner.class) @Provider(PactConstants.PACT_PROVIDER_NAME_) @PactBroker(host = PactConstants.PACT_BROKER_URL_, port = PactConstants.PACT_BROKER_PORT_, protocol = PactConstants.PACT_BROKER_PROTOCOL_) @Slf4j public class ProviderVerification { static List<Integer> objectIds = new ArrayList<Integer>(); @TestTarget public final Target target = new HttpTarget(PactConstants.TARGET_PROTOCOL_, PactConstants.TARGET_DOMAIN_, PactConstants.TARGET_PORT_); @BeforeClass public static void before() throws Exception { System.setProperty("pact.verifier.publishResults", "true"); System.setProperty("pact.provider.version", getProviderVersion()); System.out.println("Version " + getProviderVersion()); } public static String getProviderVersion() { MavenXpp3Reader reader = new MavenXpp3Reader(); try { Model model = reader.read(new FileReader("pom.xml")); return model.getParent().getVersion(); } catch (XmlPullParserException | IOException ex) { throw new RuntimeException("Error while reading POM File..."); } } @State("There is a request to get details of a Job") @Test public void testObjectsEndpoint() { http://log.info("Verifying pact provider for xyz Service"); System.out.println("Verifying pact provider for xyz Service..."); } @AfterClass public static void after(){ System.clearProperty("pact.verifier.publishResults"); System.clearProperty("providerVersion"); } }```

cjadav
2019-07-01 05:49
every time id would be different so if i use `matchPath(String pathRegex, String path)` then too it will fail

uglyog
2019-07-01 05:54
No, it will use second parameter when making the request. The ID won't change.

cjadav
2019-07-01 05:57
true but how can lets say if i use `.matchPath("/api/filter/[0-9]+","/api/filter/6",)` it will request `"/api/filter/6"` like this but my problem is that 6 might not be there at provider side so first i need to create user having id 6 and then verify the contract so how can i do this?

uglyog
2019-07-01 05:58
Use a provider state that sets up user with id 6

cjadav
2019-07-01 06:01
ok. Thanks. Do we have any example for this? sorry but i am newbie in pact

cjadav
2019-07-01 06:05
also one problem i am seeing here is that i need to create a user in provider state but as id is auto-generated, i might get 7 instead of 6 and again it will fail

uglyog
2019-07-01 06:06
`testObjectsEndpoint` is an example. It get's called when that state needs to be setup. You can create another, or rename that one (`There is a request to get details of a Job` doesn't sound useful)

cjadav
2019-07-01 06:11
Got it. Thanks. However verification will fail if generated id is 7, right?

uglyog
2019-07-01 06:12
Can you not have a user created with the correct ID?

cjadav
2019-07-01 06:12
id is auto-generated, i dont have control on it.

cjadav
2019-07-01 06:14
so at provider side sudo login would be 1. create a user in state setup 2. have this id 3. pass this in contract request /api/filter/<id> thats why i am searching a way to change pact request and pass new id

uglyog
2019-07-01 06:27
There is a new feature that allows that, but it is not documentated


cjadav
2019-07-01 06:39
is there any link for that one?

uglyog
2019-07-01 06:47
No, it's undocumented. But it allows you to pass values from the provider state callback and use them with a generator

uglyog
2019-07-01 06:47
Not sure if there are any examples either

uglyog
2019-07-01 06:50
The method is `pathFromProviderState` instead of `matchPath`

cjadav
2019-07-01 06:52
Thanks. Let me google `pathFromProviderState`

uglyog
2019-07-01 06:53
if you use `pathFromProviderState("/api/filter/${id}", "/api/filter/1")` then have your provider state method return a Map with the `id`, it will use that

uglyog
2019-07-01 06:53
You have to use the latest version of Pact-JVM

cjadav
2019-07-01 06:54
at consumer side?

uglyog
2019-07-01 06:55
Both sides

cjadav
2019-07-01 06:56
latest of `pact-jvm-consumer-junit` and `pact-jvm-provider-maven` right?

uglyog
2019-07-01 06:58
Yes. Hopefully it will work with `pact-jvm-provider-maven`, it hasn't been tested yet


cjadav
2019-07-01 06:58
let me try it

nick_horne_90
2019-07-01 09:59
has joined #pact-jvm

nick_horne_90
2019-07-01 09:59
Hi, I am trying to write a Pact-Verifying unit test for the consumer in Java. Should I only have one test per class? I have noticed that if I have multiple tests in the class some of them fail unless I add a sleep before running my client assertions.


nick_horne_90
2019-07-01 11:03
For the above im using junit 4 and my test looks like this. When I add more Pact / PactVerification pairs (more tests) then the second one seems to fail consistently unless I add a sleep. ```@RunWith(SpringRunner.class) @SpringBootTest(properties = {}) public class ConsumerPactVerificationTest { @Rule public PactProviderRuleMk2 stubProvider = new PactProviderRuleMk2("customerServiceProvider", "localhost", 8888, this); @Autowired private AddressClient addressClient; @Pact(provider = "test") public RequestResponsePact getAddresses(PactDslWithProvider builder) { return builder .given("a collection of 2 addresses") .uponReceiving("a request to the address collection resource") .path("/addresses/") .method("GET") .willRespondWith() .status(200) .body("...", "application/hal+json") .toPact(); } @Test @PactVerification(fragment = "getAddresses") public void verifyAddressCollectionPact() { assertThat(addressClient.getAddresses())... } }```

dennis.woditsch
2019-07-01 11:42
has joined #pact-jvm

dennis.woditsch
2019-07-01 11:51
Hi, I'm currently struggling with parts of the provider. We have a pact defined with a hardcoded DateTime as part of the request body. In our service we have a constraint that this has to be in the future. How can we handle this? I found something like a `@TargetRequestFilter` to modify incoming request but this seems not to work with the `SpringRestPactRunner`. Any guidance here how to handle this? Is this something we have to "fix" in our pact file or does the producer actually has to take care to modify the date to be something in the future (maybe current date + 1hour)?

cjadav
2019-07-01 12:14
I have code like ``` PactDslJsonBody body = new PactDslJsonBody() .stringValue("action","VIEW") .array("objectIds") .id(1L) .closeArray() .minArrayLike("objects",1) .id("objectId") .id("accountId") .id("ownerId") .id("workspaceId") .stringType("typeName","ASSET") .booleanValue("privateGroup", true) .booleanValue("privateCollection", true) .closeArray() .asBody();``` but after using ```<artifactId>pact-jvm-provider-maven</artifactId> <version>4.0.0-beta.3</version>``` it is generating json like ```{ "method": "POST", "path": "/api/filter/4", "headers": { "Content-Type": "application/json" }, "body": { "objects": [ { "accountId": { "value": "1234567890" }, "privateCollection": true, "typeName": "ASSET", "privateGroup": true, "ownerId": { "value": "1234567890" }, "objectId": { "value": "1234567890" }, "workspaceId": { "value": "1234567890" } } ], "action": "VIEW", "objectIds": [ { "value": "1" } ] } }``` however when i used 3.x it was generating ```{"objects":[{"accountId":4,"privateCollection":true,"typeName":"ASSET","privateGroup":true,"ownerId":5,"objectId":1,"workspaceId":3}],"action":"VIEW","objectIds":[1]}```. with 4.x version json provider verification is failing and giving ``` Returns details of the not authorised user 5 returns a response which has a matching body=BodyComparisonResult(mismatches={$=[BodyMismatch(expected=[], actual={"errorMessage":"JSON parse error: Can not deserialize instance of java.lang.Long out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.Long out of START_OBJECT token\n ```

uglyog
2019-07-01 23:56
I'm currently work on date expressions, so you can define a date as `now + 1 hour`. But it is still a work in progress. `@TargetRequestFilter` should work with `SpringRestPactRunner`, if not, that is a defect.

uglyog
2019-07-01 23:58
@cjadav could you raise a defect for that?

karlboyle
2019-07-02 15:30
has joined #pact-jvm

karlboyle
2019-07-02 15:33
Hey, just learning Pact for Jvm. I?m struggling to understand how it verifies in Maven? I can understand in junit, download pact from broker and run against a mocked instance of the app in code. But I don?t see in maven where you can spin up an instance of the app to test the pact verify against?

karlboyle
2019-07-02 15:34
Or is provider side testing with maven only for deployed/already running instances, not for dynamically spinning up your mocked instance local. Hopefully I?m making sense :)

antonello
2019-07-02 15:39
Yes, as far as I understand the maven plugin on the provider verification is only for deployed/already running instances

jdesouza
2019-07-02 17:38
has joined #pact-jvm

abubics
2019-07-03 05:42
Who uses Maven? :troll:

abubics
2019-07-03 05:43
basically, there are 2 strategies for doing JVM provider verifications: the gradle plugin way, and the junit way

abubics
2019-07-03 05:43
I can't comment on mvn, since I've never used it, but I haven't heard of a Maven version of the Gradle plugin . . . probably @uglyog would have advice there

abubics
2019-07-03 05:44
@karlboyle The way you're describing sounds like the gradle plugin workflow :slightly_smiling_face:

uglyog
2019-07-03 05:50
Maven plugin works nearly identically to the Gradle one (just in a Maven way)

karlboyle
2019-07-03 05:59
Thanks guys company requirement for Maven :zany_face:, @uglyog nearly identical - just doesn't spin up an instance? :)

uglyog
2019-07-03 06:02
Yeah, you'll need to do that using other Maven plugins. If you bind it to the integration test phase, you could use the pre- and post- phases to start and stop your app

karlboyle
2019-07-03 06:09
Ahhhh okay I'll play about later today! Thanks!

karlboyle
2019-07-03 06:17
Out of interest which is the preferred approach, provider tests in build tool or test lib. Test one seems better to me personally, just curious. Work asking about maven option hence my enquiry :)

abubics
2019-07-03 06:22
We had a little chat about this not long ago :slightly_smiling_face:

karlboyle
2019-07-03 06:36
Found it! Thanks @abubics !

cjadav
2019-07-03 08:42
Will do

sandhyarani.gabbi
2019-07-03 16:07
has joined #pact-jvm

dennis.woditsch
2019-07-05 09:09
Thanks @uglyog for your answer. This date expression would be enormously useful for us. But I guess in the meantime we have to somehow modify the date on the provider side. I tried to create a simple code snippet to show our setup. @RunWith(SpringRestPactRunner.class) @Provider("MyService") @PactBroker(host = "pact-broker.k8s.dev.XX") @ContextConfiguration(classes = { IntegrationTestWebMvcConfig.class }) @WebAppConfiguration public class PactProviderTest { @TestTarget public final MockMvcTarget target = new MockMvcTarget(); @Autowired private WebApplicationContext webApplicationContext; @Autowired private MyMock myMock; private MockMvc mockMvc; @Before public void setup() { mockMvc = webAppContextSetup(webApplicationContext) .apply(springSecurity()) .alwaysDo(log()) .defaultRequest(get("/") .servletPath("/rest")) .addFilter(new ExceptionResolverFilter(), "/*") .build(); target.setMockMvc(mockMvc); SecurityContextHolder.getContext().setAuthentication(new MockAuthentication(ORGANIZER_KEY, OAUTH_TOKEN, ORGANIZER)); } @After public void tearDown() throws Exception { myMock.reset(); } @State("default") public void blaCanBeCreated() { myMock.doUsefulSetup(); } @TargetRequestFilter public void exampleRequestFilter(HttpRequest request) { // I NEVER GET TO REACH THIS POINT } } ```

kiran.kumar.sukumar
2019-07-05 14:04
has joined #pact-jvm

kiran.kumar.sukumar
2019-07-05 14:06
Hi, How do i send a query parameter in provider side thats been set to a matcher on the consumer side e?

uglyog
2019-07-06 04:44
@kiran.kumar.sukumar when you specified the matcher on the consumer side, you can give an example value. That will be used to populate the query parameter when verifying the provider.

uglyog
2019-07-06 04:59
@dennis.woditsch `@TargetRequestFilter` will not work with `MockMvcTarget`, because there is never a real request with MockMVC. Use the `SpringBootHttpTarget` or `HttpTarget`.

uglyog
2019-07-07 08:13
3.6.11 has been released with support for date and time expressions

skirankumars31
2019-07-07 16:20
I have done that but it looks like the provide will not be able to set the exact value in provider state. The query value needs to be set to a different value when running the test. Is that possible ?

dennis.woditsch
2019-07-08 08:05
Thank you!

florian.nagel
2019-07-08 08:26
has joined #pact-jvm

dennis.woditsch
2019-07-08 08:54
This is exactly what I need. But somehow I guess I'm missing something. So I have this code in my DSLPart `body.datetimeExpression("scheduledStartTime", "today + 1 hour", "yyyy-MM-dd'T'HH:mm:ss.S'Z'");` But this is printing `"scheduledStartTime" -> "2000-01-31T14:00:00.0Z"`. What am I doing wrong here?

uglyog
2019-07-08 09:05
In the consumer test?

dennis.woditsch
2019-07-08 09:05
yes

uglyog
2019-07-08 09:07
The expressions are only used when verifying the provider side for the request.

dennis.woditsch
2019-07-08 09:12
Sure. I updated the consumer side with this datetimeExpression, updated the pact file and on provider side when I execute my tests they still get `"scheduledStartTime":"2000-01-31T14:00:00.0Z",` Dependency was also updated on the provider side

dennis.woditsch
2019-07-08 09:48
```"body": { "subject": "Meet Now", "scheduledStartTime": "2000-01-31T14:00:00.0Z", "meetingType": "scheduled" }, "matchingRules": { "body": { "$.scheduledStartTime": { "matchers": [ { "match": "timestamp", "timestamp": "yyyy-MM-dd'T'HH:mm:ss.S'Z'" } ], "combine": "AND" } } }, "generators": { "body": { "$.scheduledStartTime": { "type": "DateTime", "format": "yyyy-MM-dd'T'HH:mm:ss.S'Z'", "expression": "today + 1 hour" } }```

dennis.woditsch
2019-07-08 09:49
looks correct in the pact file. But somehow it is still wrong on the provider side

ruben.perezg
2019-07-08 11:29
Hi! I'm working trying to reach `Pact Nirvana` :slightly_smiling_face: [1], and currently trying to define our Tagging policy (for the _pact_, _consumer_ and _provider_) [2], pushing the verification results back to the broker, and also using the `can-i-deploy` tool to be sure about deploying newer versions of my services. I've found that the _gradle plugin_ [3] is able to execute the `pactVerify` task, specifying the providerName and where the Pact Broker is. But what I'm not seeing is how to connect that with my already existing tests that use either a `RestPactRunner` (JUnit 4) or a `SpringExtension`(JUnit 5). Looks like it expects that I "start up" my provider somehow [4], but I would like to use my already existing tests... Am I missing anything here? 1 -> https://docs.pact.io/best_practices/pact_nirvana 2 -> https://docs.pact.io/getting_started/versioning_in_the_pact_broker 3 -> https://github.com/DiUS/pact-jvm/tree/master/provider/pact-jvm-provider-gradle 4 -> https://github.com/DiUS/pact-jvm/tree/master/provider/pact-jvm-provider-gradle#starting-and-shutting-down-your-provider

uglyog
2019-07-08 23:52
If you are running your provider verification as JUnit tests, you don't need to use the Gradle pactVerify task. If you are using Springboot, you can use the Springboot test annotations to start the provider in the JUnit test.

asite.mshah
2019-07-09 06:05
has joined #pact-jvm

ruben.perezg
2019-07-09 06:13
I hace both scenarios: - Some as "unit tests" in the provider, using mockMVC. - Some with SpringBoot, using SpringBootTest to start the provider. But what I don't have is the results of the verification published back in the Broker. That's why I thought I needed to use the `pactVerify`... but maybe I'm wrong :smile: . Could you point me in the right direction? I think I'm missing something here, but I haven't been able to really get it with the documentation I've read


ruben.perezg
2019-07-09 08:39
ahhh, ok, I thought I had to do that in addition to using the `pactVerify` task. Thank you @uglyog :slightly_smiling_face:

uglyog
2019-07-09 23:21
Ok, can you raise an issue for that?

ruben.perezg
2019-07-10 09:04
@uglyog I still have problems... :sweat_smile: You shared the link of the `pact-jvm-provider-junit`, but I'm using `pact-jvm-provider-junit5`. I don't see anything about any JVM system property there [1]. I have tried to set it anyway with the _gradle_ execution, and haven't worked: - `./gradlew myTestTasks -Dpact.verifier.publishResults=true` I don't see any error trying to send the verification results as could be seen here [2]. I don't know how to set the `provider version` either... Could you help me with this again? :slightly_smiling_face: 1 -> https://github.com/DiUS/pact-jvm/tree/master/provider/pact-jvm-provider-junit5 2 -> https://github.com/DiUS/pact-jvm/issues/738

uglyog
2019-07-10 09:14
Can you enable debug level logs? You?ll see a message as to why it is not publishing the results.

ruben.perezg
2019-07-10 09:18
`-d`? I have, but haven't seen anything

ruben.perezg
2019-07-10 09:19
do you want me to share it?

uglyog
2019-07-10 09:19
No, you need it enabled when your tests run. The easiest way is to add logback to your test class path.

uglyog
2019-07-10 09:21
Which makes me think the property needs to be set on the test task.

ruben.perezg
2019-07-10 09:21
:thinking_face:

ruben.perezg
2019-07-10 09:34
you mean adding: ``` doFirst { System.setProperty("pact.verifier.publishResults", "true") }```

ruben.perezg
2019-07-10 09:34
inside my custom test task definition?

ruben.perezg
2019-07-10 09:35
or adding `pact.verifier.publishResults=true` in the `gradle.properties`

ruben.perezg
2019-07-10 09:36
(I have tried both, but it´s not working...)

ghandour.jihad
2019-07-10 10:20
Hello awesome pacters in https://docs.pact.io/how_pact_works I found in the "expected request" ==> (this is always present for synchronous interactions like HTTP requests, but not required for asynchronous interactions like message queues) I am interested in the second part of it... does that mean that pact works for direct java calls, that are not REST calls?

uglyog
2019-07-10 23:50
You'll need to get the debug level logs to see what is going on

uglyog
2019-07-10 23:52
If you are asking if pact could be used to test interactions between Java classes, then yes, as long as they pass JSON in string format between them

ghandour.jihad
2019-07-11 07:47
Thank you!

nick_horne_90
2019-07-11 10:20
Hey, I am writing my consumer pact, how can I set the content type if I am using `.body(DslPart)` ?

nick_horne_90
2019-07-11 10:21
It seems to set the content-type to `application/json; charset=UTF-8` but I want to set it to something else

nick_horne_90
2019-07-11 10:22
The methods with a content type don't take in the DslPart

ruben.perezg
2019-07-12 07:19
I will work on this next week, thank you very much :slightly_smiling_face:

vetisanvasile
2019-07-12 15:14
Hi all I would like to ask a question related to pact broker. I am using pact-jvm-provider-junit_2.12 (version 3.6.10) I have a provider service called "wProviderService" and two service consumers ("pConsumerOne" and "tConsumerTwo") I have defined a parameter -Dpact.broker.tags=latest in my tests My test class looks like this: @RunWith(PactRunner.class) @Provider("wProviderService") @Consumer("pConsumerOne") @PactBroker(scheme = "${pact.broker.scheme}", host = "${pact.broker.host}", tags = "${pact.broker.tags}", authentication = @PactBrokerAuth(username = "${pact.broker.user}", password = "${pact.broker.pass}")) public class PactWProviderTest{ // some dummy and uninteresting implementation } When I execute my class I notice that pact files are fetched for both consumer services not only for consumer service that I specified [@Consumer("pConsumerOne")]. Is this behaviour intended? Console output: 2019-07-12 17:58:01 [main] DEBUG a.c.d.p.p.j.loader.PactBrokerLoader ? Loading pacts from pact broker for provider "wProviderService" and tag latest 2019-07-12 17:58:01 [main] DEBUG a.c.d.pact.pactbroker.HalClientBase ? Fetching: / 2019-07-12 17:58:02 [main] DEBUG a.c.d.pact.pactbroker.HalClientBase ? Fetching: https://mypactBroker.com/pacts/provider/wProviderService/latest 2019-07-12 17:58:02 [main] DEBUG a.c.d.pact.pactbroker.HalClientBase ? Fetching: https://mypactBroker.com/pacts/provider/wProviderService/consumer/pConsumerOne/version/0.0.5-SNAPSHOT 2019-07-12 17:58:03 [main] DEBUG a.c.d.pact.pactbroker.HalClientBase ? Fetching: https://mypactBroker.com/pacts/provider/wProviderService/consumer/tConsumerTwo/version/0.0.3-1123334445

uglyog
2019-07-14 08:37
It should only be executing the pact for the one consumer. Can you confirm this?

vetisanvasile
2019-07-15 05:47
@uglyog, is this message related to the question from friday?


vetisanvasile
2019-07-15 06:10
Yes, I can confirm this it downloads pact files from other consumers too

vetisanvasile
2019-07-15 06:12
Should I create an ticket for this on https://github.com/DiUS/pact-jvm/issues?

uglyog
2019-07-15 06:59
Is it only downloading them, or is it also verifying them?

vetisanvasile
2019-07-15 06:59
just downloading them

uglyog
2019-07-15 07:00
That?s ok then

vetisanvasile
2019-07-15 07:01
~would you like to post a question on pact-jvm issues so that other users that stumble on this to have an answer?~

ruben.perezg
2019-07-16 10:02
```09:59:32.131 [Test worker] WARN a.c.d.p.p.j.TestResultAccumulator - Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true')```

ruben.perezg
2019-07-16 10:03
Now I know that I haven't been able to set the property correctly

ruben.perezg
2019-07-16 10:07
I've tried: - `-Dpact.verifier.publishResults=true` in the gradle command execution - `System.setProperty("pact.verifier.publishResults", "true")` inside our custom gradle test task Where should I set that property?

ruben.perezg
2019-07-16 10:09
The only way I've managed to set that property successfully has been setting that directly in my java tests (inside a `BeforeAll` method): I guess there should be a better way of doing this... but I haven't been able to find it

ruben.perezg
2019-07-16 10:26
Now, finally, I've been able to set it in our gradle task. The problem was that our custom gradle task was a task of type `Test`, so I needed to set the property like this, as stated here [1]: ```// set a system property for the test JVM(s) systemProperty 'some.prop', 'value'``` - https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html

ruben.perezg
2019-07-16 10:28
@uglyog do you think there is anything that I could improving in the documentation, so that it helps preventing other people from doing the same mistake? Or it is just because of my _"gradle ignorance"_ :laughing:

mui_ume
2019-07-16 10:31
Hi I?m new to the pact test on the provider side I need some simple example On java using spring and junit as framework Thanks

uglyog
2019-07-16 13:01
Anything you can do will help


mui_ume
2019-07-16 13:59
I saw this test snippet code for the login at the provider ```package xxx.platform.service.identitymanager; import xxx.platform.service.identitymanager.controller.IdentityController; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; @RunWith(SpringRunner.class) @WebMvcTest(IdentityController.class) public class IdentityControllerTest { @Autowired private MockMvc mvc; // Login Test Cases @Test public void logInUserSuccess() { //404 expected } @Test public void logInUserNotFound() { //404 expected } ```

mui_ume
2019-07-16 14:06
I did the consumer side setup for the login. my consumer is in JS. but I still trying to figure out how to add on the provider?

mui_ume
2019-07-16 14:07
above is the pact file generated by the pact test run at consumer side

mui_ume
2019-07-16 14:08
how can I replace with pact test? thanks

pavani.polakala
2019-07-16 21:52
has joined #pact-jvm

pavani.polakala
2019-07-16 21:59
Hi all. I'm new to Pact. I have configured pact on android project and tried running a sample test. But it's failing always. I'm getting this error : `java.lang.IllegalArgumentException: Could not locate ResponseBody converter for class java.lang.String` Can someone help me understand the issue?

pavani.polakala
2019-07-16 22:02
This is my request `{` ` "method": "GET",` ` "path": "/hello_world/"` `}` This is my response `{` ` "status": 200,` ` "body": "Hello World"` `}`

pavani.polakala
2019-07-16 22:03
Any help would be appreciated.

uglyog
2019-07-16 23:53
@pavani.polakala That is not anything to do with Pact. `ResponseBody converter` must be something from the android libraries you are using.


pavani.polakala
2019-07-17 00:00
Thanks @uglyog

florian.nagel
2019-07-17 09:10
I am analysing Consumer-driven contract tests in the scope of my bachelor thesis and I was wondering if it would (technically) be possible for the Gradle plugin to listen (and maybe trigger an event) to a Kafka topic. This way the pact framework would behave just like in the synchronous way and would actually trigger the event. This would make it easier for Pact integration in testing. I'd be glad for any input on this and am open to discussion on how to best incorporate pact testing (i.e. CDCs) in an asynchronous environment, preferably Kafka.

florian.nagel
2019-07-17 09:11
I suppose this could also go into #general as well. I can post this again if the mods think it is suited for #general

sabil.beladri
2019-07-17 14:11
has joined #pact-jvm

pavani.polakala
2019-07-17 18:19
@uglyog How to include tag in the publishing task in JVM?

pavani.polakala
2019-07-17 18:22
Got it.

uglyog
2019-07-18 00:04
I think this is a good topic for general. But back to the Gradle plugin, the reason why we kept things agnostic to queues otherwise the pact libraries would have to know about every queue available.

denis.ducansel
2019-07-18 09:30
has joined #pact-jvm

sabil.beladri
2019-07-18 14:10
Hi! First of all kudos to Pact foundation for providing such powerful tools. Glad to be using pact over the last year, it makes a huge difference and leap forward within my organization. I have questions specific to pact-jvm-provider-spring: I'm using MockMvcTarget and upon running pact validation I get these errors: * comparison -> Expected a response type of 'application/json' but the actual type was 'text/plain' * Expected a header 'Content-Type' but was missing Any suggestion/hint? Thanks for keeping me posted if so!

pavani.polakala
2019-07-18 14:44
@uglyog Pact file is always generated in target/pacts. I want it to be generated in build directory. I used following to change it 1. `System.setProperty(PactConsumerConfig.pactRootDir(), "build/pacts");` 2.`ext { pactDirectory = "$buildDir/pacts" }` But its not working. When I did debug, I found this in MockHttpServer.kt which overrided my values. `fun pactDirectory() = System.getProperty("pact.rootDir", "target/pacts")!!`

pavani.polakala
2019-07-18 14:46
Any idea on how to change the directory?

abubics
2019-07-19 00:25
I think you probably want ``` System.setProperty("pact.rootDir", "build/pacts"); ```

abubics
2019-07-19 00:25
the second argument to `System.getProperty` is the fallback, if the property isn't set

matt.fellows
2019-07-19 05:40
@matektchorek let?s continue your discussion in a thread here (to avoid polluting general)

matektchorek
2019-07-19 05:40
has joined #pact-jvm


matt.fellows
2019-07-19 05:41
Carry on here?

matt.fellows
2019-07-19 05:41
(I have to head to a meeting?)

matektchorek
2019-07-19 06:02
is there a possibility to mock server with my own jar file instead?

guidopio.mariotti10_d
2019-07-19 07:30
Hi, is there anyone that can look into https://github.com/DiUS/pact-jvm/issues/903#issuecomment-512142413? I think the gradle plugin was compiled with Java 12

tchorek.mateusz
2019-07-20 09:19
has joined #pact-jvm

guidopio.mariotti10_d
2019-07-21 06:40
Can anyone spot what is wrong in the timestamp format? ``` expected="2000-01-31T14:00:00.000+01:00", actual="2019-07-21T08:38:12.087+02:00", mismatch=Expected "2019-07-21T08:38:12.087+02:00" to match a timestamp of 'YYYY-MM-DD'T'HH:mm:ss.SSSZZZ': Unable to parse the date: 2019-07-21T08:38:12.087+02:00 ``` My guess is on the `SSSZZZ` but I?m not able to figure out what is wrong

uglyog
2019-07-21 07:01
Use `XXX` instead of `ZZZ`

uglyog
2019-07-21 07:04
I just double checked the Java docs, and `ZZZ` does not accept the zone offset with a colon. It expects `+0200` form

guidopio.mariotti10_d
2019-07-21 07:22
It doesn?t seem to make a difference. It still produces the same example date but with the same error too

guidopio.mariotti10_d
2019-07-21 07:22
Do you know which class is used for the validation? I wanted to debug this but I?m having an hard time finding the right class in the provider library

mui_ume
2019-07-22 06:16
Hi, what should I put at @Provider("pricing") for my use case?

mui_ume
2019-07-22 06:16
pricing is to be replaced with ?

mui_ume
2019-07-22 06:17
Also I have setup my own pact broker at https://pact.shared.frigg.li/

mui_ume
2019-07-22 06:17
@PactBroker(protocol = "https", host = "${pactBrokerHost}", port = "443", authentication = @PactBrokerAuth(username = "${pactBrokerUser}", password = "${pactBrokerPassword}"))

mui_ume
2019-07-22 06:19
can I just use this: ```@PactBroker("https://pact.shared.frigg.li/")```

mui_ume
2019-07-22 06:20
I guess the "pricing" should replaced with my provider name?

mui_ume
2019-07-22 06:21
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)

mui_ume
2019-07-22 06:21
I do not understand what is this WebEnvironment.DEFINED_PORT

mui_ume
2019-07-22 06:48
is there any simpler example to add the pact test code for the provider. I do not understand those @State annotation as seen in this github example: https://github.com/DiUS/pact-jvm/blob/master/provider/pact-jvm-provider-junit/src/test/java/au/com/dius/pact/provider/junit/ArticlesContractTest.java

mui_ume
2019-07-22 06:48
I only want to verify this provider's response: ```{ "status": 200, "headers": { "Content-Type": "application/json" }, "body": { "authToken": "eyJraWQiOiJVdEI4c0hhYnk0aXBLNlwvQTZnaHBkRFFqRU9tdlptSnZZQTJpNFwvM2w3UmM9IiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiIyMTVhMGVhZS00ZjkwLTRlODItOWY4Zi1lNzhlOTdkMzcyODAiLCJldmVudF9pZCI6IjQxMjA3MjQwLWI2NGEtNDYxNi1iOGFiLTJkYzNiZjY4YWEwNCIsInRva2VuX3VzZSI6ImFjY2VzcyIsInNjb3BlIjoiYXdzLmNvZ25pdG8uc2lnbmluLnVzZXIuYWRtaW4iLCJhdXRoX3RpbWUiOjE1NjEwOTUwMDYsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC51cy1lYXN0LTIuYW1hem9uYXdzLmNvbVwvdXMtZWFzdC0yX2EzbE5SRU5QMSIsImV4cCI6MTU2MTA5ODYwNiwiaWF0IjoxNTYxMDk1MDA2LCJqdGkiOiJlNGFiNTI0Ny1hZjgwLTQ1MmUtOTcwMS01YjQ4OTY1ZTcwZDgiLCJjbGllbnRfaWQiOiI2Z2xwbmRxb2s2YWhua3M2dGFnNXQ5cGMwZyIsInVzZXJuYW1lIjoicWFAdGVsZXBhdGh5LmFpIn0.icFT50MVM-xhAPIu76H9XwIeNHhbe6_d3LcAv1qDQcRp1xabxpgzntgaEvyUnaTwFFJzkU2flfIrT_Y8TCeeFFqMFrMkpS9GadVtraxpOtNhMwxrwUz6bbz8iMHFxSxcIi0Ar3y06RLoRkp3C4gXf7eL8JXsTI9IB56TK7idvUmUcbN_322UPsAU98l3XFjdQEkMo3Fnqyrr41ftWBH876E2KB4g79Q73AL_s0j7mRmXjGswu8-pFiyPcIrDZKz35RSEpdWYLoRyW8rDnYU6YqWM-ncXEczBKlBKk6ggxMOK_qcTc7HYBty9c16zOn-33hxLCxG6pOtg5vLD3L0Tqw", "clientInfo": { "clientId": "0662923d-b187-4879-866a-3f053178426a" } } }```

florian.nagel
2019-07-22 08:24
I get timeouts when using the 4.x version with both the gradle plugin and the jUnit 5 runner. Gradle `pactVerify` works fine with 3.6.12 but fails to work with 4.0.0-beta.4 or 4.0.0-beta.3. I have written a class to be used by the gradle test and a class to be used with jUnit 5. I really don't know what to do. When jUnit5 is used it proceeds to `context.verifyIntegration()` and then times out, or to be more specific has an exception because the heap space is exceeded. When used with the gradle plugin there is a timeout as well, but it says `Expiring Daemon because JVM Tenured space is exhausted`. You could say "just use the gradle plugin" as it works fine, but I need an EmbeddedKafkaBroker which needs spring class annotations and I can only do that with the junit5 support. When I use the older version (3.6.x) of the jUnit5 runner it doesn't recognize any pact syntax/classes in my test class. As you see I'm running into multiple walls. Any help is appreciated. I'll post my source code on request.

florian.nagel
2019-07-22 12:59
Same project as above, different issue: My project is using an embeddedKafka with spring. When I use `pact-jvm-provider-junit5_2.12:3.5.24` everything's fine on pact side. But the context of the spring project won't load. As soon as I add the line ```implementation 'org.scala-lang:scala-library:2.11.8'``` in the gradle build file the pact test throws the following error message `java.lang.NoSuchMethodError: com.typesafe.scalalogging.StrictLogging.$init$(Lcom/typesafe/scalalogging/StrictLogging;)V` I can add the stacktrace if you want. When using `pact-jvm-provider-junit5_2.12:3.6.12` I get the following error: `java.lang.NoSuchMethodError: com.typesafe.scalalogging.StrictLogging.$init$(Lcom/typesafe/scalalogging/StrictLogging;)V` I have the feeling that this all has to do with a scala version mismatch but I am unable to figure this out unfortunately. Any help is appreciated.

florian.nagel
2019-07-22 13:00
So to clarify the original thread, both, the gradle plugin and the jUnit5 runner time out when using version `4.0.0-beta.4`

igordezky
2019-07-22 17:55
has joined #pact-jvm

uglyog
2019-07-22 22:22
What jvm version are you using?

mui_ume
2019-07-23 04:42
Hi here is my provider pact test code: ```package package xxx.xxx.platform.service.identitymanager.pact; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import javax.ws.rs.ext.Provider; @RunWith(SpringRestPactRunner.class) @Provider("Platform Services") @PactFolder("pacts") @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class LoginProviderPactTest { @TestTarget public final Target target = new SpringBootHttpTarget(); } ```

mui_ume
2019-07-23 04:44
I got a compilation error ```[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile (default-testCompile) on project identity-manager: Compilation failure [ERROR] /Users/core-develop/platform/service/identity-manager/src/test/java/xxx/xxxx/platform/service/identitymanager/pact/LoginProviderPactTest.java:[1,8] <identifier> expected```

mui_ume
2019-07-23 04:44
what did I miss?

mui_ume
2019-07-23 04:46
in my pact json, I have a few request/response endpoints with the same URL, how do I write my provider pact test for one of the request/response endpoint?

mui_ume
2019-07-23 04:46
the github examples are not cleared to me how I should write the provider pact test code.

mui_ume
2019-07-23 04:48
basically, I just want to verify this response at the pact file ``` { "description": "authToken and clientInfo clientId", "request": { "method": "POST", "path": "/api/identity-manager/v2/login", "headers": { "Accept": "*/*", "Content-Type": "application/json" }, "body": { "clientInfo": { "clientId": null }, "pass": "xxxxxx!", "tenantId": "xxx", "userId": "xxx@xxxx" }, "matchingRules": { "$.body": { "match": "type" } } }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": { "authToken": "eyJraWQiOiJVdEI4c0hhYnk0aXBLNlwvQTZnaHBkRFFqRU9tdlptSnZZQTJpNFwvM2w3UmM9IiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiIyMTVhMGVhZS00ZjkwLTRlODItOWY4Zi1lNzhlOTdkMzcyODAiLCJldmVudF9pZCI6IjQxMjA3MjQwLWI2NGEtNDYxNi1iOGFiLTJkYzNiZjY4YWEwNCIsInRva2VuX3VzZSI6ImFjY2VzcyIsInNjb3BlIjoiYXdzLmNvZ25pdG8uc2lnbmluLnVzZXIuYWRtaW4iLCJhdXRoX3RpbWUiOjE1NjEwOTUwMDYsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC51cy1lYXN0LTIuYW1hem9uYXdzLmNvbVwvdXMtZWFzdC0yX2EzbE5SRU5QMSIsImV4cCI6MTU2MTA5ODYwNiwiaWF0IjoxNTYxMDk1MDA2LCJqdGkiOiJlNGFiNTI0Ny1hZjgwLTQ1MmUtOTcwMS01YjQ4OTY1ZTcwZDgiLCJjbGllbnRfaWQiOiI2Z2xwbmRxb2s2YWhua3M2dGFnNXQ5cGMwZyIsInVzZXJuYW1lIjoicWFAdGVsZXBhdGh5LmFpIn0.icFT50MVM-xhAPIu76H9XwIeNHhbe6_d3LcAv1qDQcRp1xabxpgzntgaEvyUnaTwFFJzkU2flfIrT_Y8TCeeFFqMFrMkpS9GadVtraxpOtNhMwxrwUz6bbz8iMHFxSxcIi0Ar3y06RLoRkp3C4gXf7eL8JXsTI9IB56TK7idvUmUcbN_322UPsAU98l3XFjdQEkMo3Fnqyrr41ftWBH876E2KB4g79Q73AL_s0j7mRmXjGswu8-pFiyPcIrDZKz35RSEpdWYLoRyW8rDnYU6YqWM-ncXEczBKlBKk6ggxMOK_qcTc7HYBty9c16zOn-33hxLCxG6pOtg5vLD3L0Tqw", "clientInfo": { "clientId": "0662923d-b187-4879-866a-3f053178426a" } }, "matchingRules": { "$.body": { "match": "type" } } } } ],```

guidopio.mariotti10_d
2019-07-23 07:43
I tried parsing that date with that format using a `FastDateFormat` instance and no exceptions are thrown. Is it the matcher using something else?

uglyog
2019-07-23 08:27
What version of Pact-JVM are you using?


florian.nagel
2019-07-23 10:12
Should be 1.8, not at my work laptop at the moment. So I can't check. Thanks for the quick reply! I'll let you know as soon as I had a chance to check @uglyog

guidopio.mariotti10_d
2019-07-23 12:07
4.0.0-beta.4. I?ll try to debug it and let you know what is the problem

guidopio.mariotti10_d
2019-07-23 14:06
ok, all of a sudden now the timestamp matching works. I found that the only problem was when milliseconds is 0 and jackson serialization removes it

oswald.quek
2019-07-23 15:51
.

oswald.quek
2019-07-23 15:53
is it because you have `package package xxx...`?

uglyog
2019-07-23 23:00
Ah, yeah, the JVM date time formats don?t support any optional fields which can be annoying. Especially the milliseconds field.

mui_ume
2019-07-24 01:42
thanks I fixed that, but my test still fail not due to pact...

mui_ume
2019-07-24 07:16
I have this build error when build pact test java.lang.IllegalStateException: Failed to load ApplicationContext Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vaultReactiveBootstrapConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.vault.config.VaultReactiveBootstrapConfiguration$$EnhancerBySpringCGLIB$$34b3cdf1]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: reactor/ipc/netty/http/client/HttpClientOptions$Builder Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.vault.config.VaultReactiveBootstrapConfiguration$$EnhancerBySpringCGLIB$$34b3cdf1]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: reactor/ipc/netty/http/client/HttpClientOptions$Builder Caused by: java.lang.NoClassDefFoundError: reactor/ipc/netty/http/client/HttpClientOptions$Builder Caused by: java.lang.ClassNotFoundException: reactor.ipc.netty.http.client.HttpClientOptions$Builder

florian.nagel
2019-07-24 07:16
@uglyog It is indeed version 1.8 Just checked

uglyog
2019-07-24 07:17
@mui_ume you must be missing a dependency -> `java.lang.ClassNotFoundException: reactor.ipc.netty.http.client.HttpClientOptions$Builder`

uglyog
2019-07-24 07:18
This is not anything to do with Pact

florian.nagel
2019-07-24 07:24
Yeah. That's what I thought. Would still be nice to have the same ease of access as with the REST protocol. So for example just defining the kafka topic Pact should listen on and then reading that out. Would be awesome, but I totally get your point.

florian.nagel
2019-07-24 07:33
I think I have found the reason for the timeout. I get lots of errors regarding the file system. That I can't open certain files. Apparently Pact is searching each and every file in my gradle user cache. Version 4.0.0-beta.3 and up don't print those errors to the console and, as there are lots of them, the heap space is exceeded. When using version 4.0.0-beta.1 it works because every error is printed to the console. Still annoying as hell, but at least the pact verification works. I still have no idea why I get all the errors. This is the error message I get. Might have nothing to do with Pact, but you never know ```org.reflections.ReflectionsException: could not create class object from file com/ibm/icu/impl/data/icudt61b/zone/en_001.res``` Imagine this message with a whole stacktrace for *a lot* of files. I'm looking into it as we speak, but I thought I'd let you guys know anyway

florian.nagel
2019-07-24 07:42
That's the complete stacktrace, in case someone needs it.

florian.nagel
2019-07-24 07:49
My uninformed guess is that it has to do with the method annotation scanner of pact. Somehow it is looking into *all* files and not just looking for the annotated method in the same class. This is using `jUnit` btw

mui_ume
2019-07-24 09:16
ok got it, fixed by adding the dependencies...

mui_ume
2019-07-24 10:11
my provider pact test is failing, it is not reading from the pact file

mui_ume
2019-07-24 10:12
I put the pact file at ~/src/test/resources/pacts/mypact.json

mui_ume
2019-07-24 10:14
my pact java class file is at ~/src/test/java/xx/xxx/xxx/xxx/xxx/pact/ProviderPactTest.java

mui_ume
2019-07-24 10:14
@PactFolder("pacts")

florian.nagel
2019-07-24 10:33
I had the exact same problem. Which version of pact are you using? For me it worked when I specified it as a PactUrl. ```@PactUrl(urls = {"D:\\src\\test\\resources\\pacts\\pact.json"})``` This is not a good fix of course, but it is a workaround if you want to test your provider tests quick and dirty. Let me know if you've got it to work with the `@PactFolder` annotation. @mui_ume


mui_ume
2019-07-24 12:42
to add to the pom.xml

mui_ume
2019-07-24 12:42
```<plugin> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>4.0.0</version> <configuration> <serviceProviders> <!-- You can define as many as you need, but each must have a unique name --> <serviceProvider> <name>Platform Services</name> <!-- All the provider properties are optional, and have sensible defaults (shown below) --> <pactFileDirectory>/Users/tohlaymui/Desktop/ai.telepathy.core-develop/platform/service/identity-manager/src/test/resources/pacts </pactFileDirectory> </serviceProvider> </serviceProviders> </configuration> </plugin>```

mui_ume
2019-07-24 12:43
but I got [ERROR] Errors: [ERROR] ProviderPactTest.initializationError » Exactly one pact source should be set

florian.nagel
2019-07-24 12:43
Ah okay. I thought you were working with the method annotations of jUnit for example

mui_ume
2019-07-24 12:47
my pact broker is setup at https://pact.shared.frigg.li/

mui_ume
2019-07-24 12:47
how can I specify to point to this?

mui_ume
2019-07-24 13:19
question: the endpoint in my json file is "path": "/api/identity-manager/v2/login",

mui_ume
2019-07-24 13:19
so I need to bring up this endpoint for pact test to pass?

sandhyarani.gabbi
2019-07-24 19:28
Hi, I have a scenario where a date field on the provider side is expecting the date to be in future and within 40 days from the current date. If I am setting the value on consumer side as currenttime + 5 mins but the verification is failing(with error "date must be in future") as it is done after 24 hours. How do I deal with this scenario?

uglyog
2019-07-24 23:16
Yes, your service needs to be running

uglyog
2019-07-24 23:17
Back to the path problem, with Gradle it works relative to the resources folder. It must be something Maven is doing different.


uglyog
2019-07-24 23:19
What are you using to set currenttime + 5 mins ? Is that what is going into the pact file?

mui_ume
2019-07-25 05:17
ok, I have added this to my pom.xml ``` <plugin> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>4.0.0</version> <configuration> <serviceProviders> <serviceProvider> <name>spring-boot-maven-provider</name> <pactFileDirectory>src/test/resources/pacts</pactFileDirectory> </serviceProvider> </serviceProviders> </configuration> </plugin>```

mui_ume
2019-07-25 05:18
when I run mvn test I got this ```[ERROR] Failures: [ERROR] ProviderPactTest.UI Client - authToken and clientInfo clientId 0 - expected status of 200 but was 404 1 - BodyComparisonResult(mismatches={$=[BodyMismatch(expected={"authToken":"eyJraWQiOiJVdEI4c0hhYnk0aXBLNlwvQTZnaHBkRFFqRU9tdlptSnZZQTJpNFwvM2w3UmM9IiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiIyMTVhMGVhZ....```

mui_ume
2019-07-25 05:18
does it mean it has read the pact file but it could not pass due to the endpoint services not up and running?

uglyog
2019-07-25 05:20
No, it made the request, but got a 404 response instead of the expected 200

mui_ume
2019-07-25 08:30
my request ``` "request": { "method": "POST", "path": "/api/identity-manager/v2/login", "headers": { "Accept": "*/*", "Content-Type": "application/json"```

mui_ume
2019-07-25 08:30
is it that I got to specify the local host url?

mui_ume
2019-07-25 08:31
I saw this from the log file ```Fetching config from server at : http://localhost:8888```

uglyog
2019-07-25 08:33
You need to tell pact where your server is running. You can do that in the maven config. It will default to 8080 otherwise


sandhyarani.gabbi
2019-07-25 08:39
I am setting it manually and yes it is going into the pact file and verification passes if it is done within 5 mins and fails when verified after 5 mins

mui_ume
2019-07-25 08:40
I add these lines to the nearest pom.xml ``` <plugin> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>4.0.0</version> <configuration> <serviceProviders> <serviceProvider> <name>spring-boot-maven-provider</name> <pactFileDirectory>src/test/resources/pacts</pactFileDirectory> </serviceProvider> <serviceProvider> <name>Platform Services</name> <protocol>http</protocol> <host>localhost</host> <port>8888</oport> <path>/</path> </serviceProvider> </serviceProviders> </configuration> </plugin>```

uglyog
2019-07-25 08:42
Add the port to the first serviceProvider

mui_ume
2019-07-25 08:43
is the serviceProvider the name of my Provider "Platform Services"? or "identity-manager"?

mui_ume
2019-07-25 08:44
my pact file : ``` "consumer": { "name": "UI Client" }, "provider": { "name": "Platform Services" }, "interactions": [...```

mui_ume
2019-07-25 08:48
my pom.xml: ``` <plugin> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>4.0.0</version> <configuration> <serviceProviders> <serviceProvider> <name>spring-boot-maven-provider</name> <protocol>http</protocol> <host>localhost</host> <port>8888</port> <path>/</path> <pactFileDirectory>src/test/resources/pacts</pactFileDirectory> </serviceProvider> </serviceProviders> </configuration> </plugin>```

mui_ume
2019-07-25 08:48
not sure if this is correct but my test still failed with status 404

uglyog
2019-07-25 08:48
"Platform Services"

mui_ume
2019-07-25 08:49
okay

uglyog
2019-07-25 08:49
Is it running on that port? What do you get if you make that request with curl or postman?

mui_ume
2019-07-25 08:49
I replaced with <name>spring-boot-maven-provider</name> with <name>Platform Services</name>

mui_ume
2019-07-25 08:53
if I used the extra url and endpoint on postman, I got status 200 and the response ```{ "authToken": "eyJraWQiOiJVdEI4c0hhYnk0aXBLNlwvQTZnaHBkRFFqRU9tdlptSnZZQTJpNFwvM2w3UmM9IiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiJhM2FiMzZiYy0wZGM1LTQxNzctOGIwMC02NzQ4ZDFiOWVjN2EiLCJjb2duaXRvOmdyb3VwcyI6WyJyb290Il0sImV2ZW50X2lkIjoiZmY4Y2JkZWQtNjQ3MS00YWMxLWExZWMtZTI3NGQ0NDhhYWFlIiwidG9rZW5fdXNlIjoiYWNjZXNzIiwic2NvcGUiOiJhd3MuY29nbml0by5zaWduaW4udXNlci5hZG1pbiIsImF1dGhfdGltZSI6MTU2NDA0MDU0MSwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMi5hbWF6b25hd3MuY29tXC91cy1lYXN0LTJfYTNsTlJFTlAxIiwiZXhwIjoxNTY0MDQ0MTQxLCJpYXQiOjE1NjQwNDA1NDEsImp0aSI6IjI2ZDk1MzYxLTU0OTUtNDA0My05YWZmLTQyYjQ3NjFmNGU1MCIsImNsaWVudF9pZCI6IjZnbHBuZHFvazZhaG5rczZ0YWc1dDlwYzBnIiwidXNlcm5hbWUiOiJsYXltdWkudG9oQHRlbGVwYXRoeS5haSJ9.MINll4bAg5gzQf4Jf4f4p1N6iyLQoiBkJLMYXEaJU4fdjWYEKpZi_45ZHYHp0yr9SiMnWqW97AEJR9orE1190F45STSjy8ApsMjNcH6b7m1UajbE9WWhfXC3kicD2JRvKlptazIpCllH8Jal-XU9XtpZ7fUmkUWFlk9e5FtJ-6yoU639PkeYzjtwPK9jwPPzOr1paxqxwcnJmofUhj1HoELsBjzoXOJANUMq0GYaOCKrd3i-o9gBNBtVY3Wa4b9u-V2HkG9hAh3e-R7Fck78vIJgVg0xsdPmyPR6daCz1Abkcu1VPfpvcpu3Lt92xMB1KdTrUxVQ9rvYBvWHSshgVA", "clientInfo": { "clientId": "dafbbd50-b2d7-442f-941b-40269be61ac9" } }```

mui_ume
2019-07-25 08:54
I will try with that local host and port

mui_ume
2019-07-25 08:57
it didn't work

mui_ume
2019-07-25 09:07
I just realised the identity-manager is not up and running, thus the pact test fail

jgluck
2019-07-25 17:20
has joined #pact-jvm

jgluck
2019-07-25 17:39
Okay, I'm here after a few hours of confusion. Disclaimer: I'm a very experienced developer but I'm rusty with Java and have limited experience with SpringBoot. I have some Spring experience, but again, it's rusty. I have experience implementing pact in Ruby. I (think I am/intend to on) using SpringBoot 1.5 Java 8 Pact 3.6.11 (because we can't use beta versions of software here) JUnit4 Pact Broker Maven I have implemented to consumer side of pact for a POC I am doing. I am now attempting to implement the provider side My provider class looks like this ``` import au.com.dius.pact.provider.junit.Provider; import au.com.dius.pact.provider.junit.State; import au.com.dius.pact.provider.junit.loader.PactBroker; import au.com.dius.pact.provider.junit.target.Target; import au.com.dius.pact.provider.junit.target.TestTarget; import au.com.dius.pact.provider.spring.SpringRestPactRunner; import au.com.dius.pact.provider.spring.target.SpringBootHttpTarget; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; @RunWith(SpringRestPactRunner.class) @PactBroker( host = "localhost", port ="9292") @Provider("legal-agreement-service") @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) public class AgreementTypeResourceProviderStatesTest { @TestTarget public final SpringBootHttpTarget target = new SpringBootHttpTarget(); } ``` My pom plugin config looks like this ``` <plugin> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-provider-maven_2.12</artifactId> <version>3.6.11</version> <configuration> <serviceProviders> <serviceProvider> <pactBrokerUrl>http://localhost:9292</pactBrokerUrl> <name>legal-agreement-service</name> <protocol>http</protocol> <host>localhost</host> </serviceProvider> </serviceProviders> </configuration> </plugin> ```

jgluck
2019-07-25 17:40
When I run `mvn test-compile pact:verify` I Get the following error ``` Verifying a pact between borrower and legal-agreement-service [from Pact Broker http://localhost:9292/pacts/provider/legal-agreement-service/consumer/borrower/version/163.0-SNAPSHOT] Given test GET WARNING: State Change ignored as there is no stateChange URL GET REQUEST Jul 25, 2019 10:33:34 AM org.apache.http.impl.execchain.RetryExec execute INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://localhost:8080: The target server failed to respond Jul 25, 2019 10:33:34 AM org.apache.http.impl.execchain.RetryExec execute INFO: Retrying request to {}->http://localhost:8080 Jul 25, 2019 10:33:34 AM org.apache.http.impl.execchain.RetryExec execute INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://localhost:8080: The target server failed to respond Jul 25, 2019 10:33:34 AM org.apache.http.impl.execchain.RetryExec execute INFO: Retrying request to {}->http://localhost:8080 Jul 25, 2019 10:33:34 AM org.apache.http.impl.execchain.RetryExec execute INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://localhost:8080: The target server failed to respond Jul 25, 2019 10:33:34 AM org.apache.http.impl.execchain.RetryExec execute INFO: Retrying request to {}->http://localhost:8080 Request Failed - localhost:8080 failed to respond [WARNING] Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true') Failures: 0) Verifying a pact between borrower and legal-agreement-service - GET REQUEST Given test GET localhost:8080 failed to respond [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 02:24 min [INFO] Finished at: 2019-07-25T10:33:34-07:00 [INFO] Final Memory: 78M/244M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal au.com.dius:pact-jvm-provider-maven_2.12:3.6.11:verify (default-cli) on project legal-agreements-server-pact: There were 1 pact failures -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException ``` I've tried numerous things but I'm just stabbing in the dark. I'm unable to find anything documented examples that are specific to my stack. I'm wondering if anyone can either point me to some docs that are known to be good, or help me work out the kinks. I'm trying to figure out if I'm having a port problem or a mock target setup problem. Also note that our implementation is not a strict SpringBoot implementation in that they aren't using @Service or @SpringBootApplication annotations. But I'm not sure that is even what the problem is. At this point, I'd simply like to prove to myself that I can get a minimal setup to work. Any takers?

jgluck
2019-07-25 21:06
Correction. I appear to be using SpringBoot 1.25

jgluck
2019-07-25 22:43
So that means that part of my problem is that I can't use @LocalServerPort. Instead, I'm attempting to use ``` @Value("${local.server.port}") private int port;```

uglyog
2019-07-25 22:51
@jgluck can you check what port your app is running on? Also, it looks like you have both a unit test and are using the maven plugin.

uglyog
2019-07-25 22:51
You normally only need to do one of the other


uglyog
2019-07-25 22:52
I have working example projects, but they will be springboot 2

jgluck
2019-07-25 22:53
I'd like the test to start the app

jgluck
2019-07-25 22:53
If you have a working example, I'd love to see it

jgluck
2019-07-25 22:53
So in other words, I use the plugin if the app is already running?


jgluck
2019-07-25 22:56
Yeah, also kotlin.

jgluck
2019-07-25 22:57
Oh, hmmm, so if I want to use the mojo, I can only use it with already running app?

uglyog
2019-07-25 22:57
Yes, you'll have to use maven plugins to start and stop the app, or some other mechanism

uglyog
2019-07-25 22:58
I think the recommended way would be to bind the Maven Mojo to the integration test phase and then you can use the pre-.post- phases to start and stop the app

uglyog
2019-07-25 22:58
Or you can use a script

jgluck
2019-07-25 23:01
sure that makes sense

jgluck
2019-07-25 23:01
Otherwise I'm just driving it with surefire verify?

jgluck
2019-07-25 23:06
Okay, great. Yes, I was very confused. I get it now, I think

jgluck
2019-07-25 23:08
I think I'm going to skip the mojo and try to use webEnvironment. Wish me luck

uglyog
2019-07-25 23:08
If you're not using the @SpringBootApplication annotation, you'll need to check that the test is bootstrapping the spring context correctly

jgluck
2019-07-25 23:13
Sure, there's some tests in here I can use for reference. Makes it a little more challenging. Of course, some of our project are using CDC so we're going to try to encourage teams to upgrade by letting them know they can use the pact broker on existing contract tests if the upgrade to SpringBoot 2.0, as it is my understanding that the broker is supported in SpringBoot 2.0

jgluck
2019-07-25 23:17
So do I remove the plugin entirely? Or do I use it to set the location of the broker?

uglyog
2019-07-25 23:18
The broker details can be driven with annotations, no need for the plugin

hvgiitr
2019-07-26 04:18
has joined #pact-jvm

au443479
2019-07-26 05:58
has joined #pact-jvm

guidopio.mariotti10_d
2019-07-26 07:55
Hi, I?m having a problem when trying to publish the verification results using the gradle plugin, version `4.0.0-beta.4`. The function `publishingResultsDisabled()` always returns true even if the property is correctly set. The image is me trying to debug this issue. Any guess on what I might be doing wrong?

uglyog
2019-07-26 08:35
How are you running the tests?

guidopio.mariotti10_d
2019-07-26 08:42
I?m running the following task `./gradlew :varkyrie:pactVerify -Dpact.verifier.publishResults=true`. `valkyrie` is a module in my project

uglyog
2019-07-26 08:52
Hmm, that looks all ok

uglyog
2019-07-26 08:53
Are you able to run it with version 3.6.12?

guidopio.mariotti10_d
2019-07-26 08:59

sandhyarani.gabbi
2019-07-26 14:06
@matt.fellows @uglyog Can someone please help me with this

florian.nagel
2019-07-26 14:48
@uglyog If you have any input it'd be very much appreciated

jgluck
2019-07-26 22:24
By any chance, will someone confirm what the lowest version of SpringBoot I need in order to run the spring pact provider without conflicts? My project is currently using 1.2.5 which I understand is very very old. It appears to me that even the oldest versions of pact require a minimum Spring Boot version of 1.5.14 (and yes I realize 1.x will be EOL in two weeks). I'd like confirmation partly as ammunition for convincing my boss that we need to upgrade our base dependency package.

uglyog
2019-07-27 02:38
When using the Gradle plugin, you need to use `-P` instead of `-D`. Must be because the plugin runs as part of the main Gradle process.

uglyog
2019-07-27 02:46
The pact-jvm-provider-spring is currently built against spring-boot-starter-test 1.5.16.RELEASE. But it comes down to the version of spring-test that is transitively used. For older versions of Springboot, if they so not work you could just use the Gradle or Maven plugin to run the verification.

uglyog
2019-07-27 02:51
You could try build that module against Springboot 1.2.5. The main classes used are: - org.springframework.beans.BeanUtils - org.springframework.test.context.TestContextManager - org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks - org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks - org.springframework.test.context.support.DependencyInjectionTestExecutionListener - org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener - org.springframework.test.context.support.DirtiesContextTestExecutionListener - org.springframework.test.context.web.ServletTestExecutionListener - org.springframework.core.env.Environment If those classes haven't changed much, then it may work

uglyog
2019-07-27 03:48
There is a new feature in Pact-JVM you can use. Have a read through https://blog.pactflow.io/dealing-with-relative-dates-in-contract-tests/

florian.nagel
2019-07-29 07:21
I am still having this issue. If anyone has any input I'd be very grateful

guidopio.mariotti10_d
2019-07-29 08:10
the `-P` makes `Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true')` disappear, however, in the pact broker, the `Last Verified` field is not updated

uglyog
2019-07-29 08:12
If you enable debug level logging, you should see the log entries with the post of the results

guidopio.mariotti10_d
2019-07-29 09:05
actually, I just discovered that when it runs in our pipeline, the `Last Verified` field is properly updated

guidopio.mariotti10_d
2019-07-29 09:05
not sure, however, what is the different with running it locally

guidopio.mariotti10_d
2019-07-29 09:10
found the problem, locally I receive a 307 as response status code, could it be the reason?

deshdeepdivakar
2019-07-30 07:35
has joined #pact-jvm

deshdeepdivakar
2019-07-30 07:35
hi @here can someone please point me to a good provider (Spring + JUnit 5) example. I am a bit confused as all the current JUnit examples are using Wiremock & I have my service running locally as a gradle task. Do I need to have my consumer mocked when verifying provider :thinking_face: Also,`org.junit.platform.commons.util.PreconditionViolationException: No supporting TestTemplateInvocationContextProvider provided an invocation context` getting this error https://github.com/DiUS/pact-jvm/blob/master/provider/pact-jvm-provider-junit5/src/test/java/au/com/dius/pact/provider/junit5/HttpsContractTest.java



sabil.beladri
2019-07-30 08:07
Hi, a question regarding RestPactRunner usage: I have a service provider receiving 2 pacts, each for a different controller I'm facing the issue that if pact is declared for the same provider name, I can't setup each controller separately where my @RunWith(RestPactRunner.class) is declared. So I had to split each pact with a different provider declaration (myServiceProviderControllerA and myServiceProviderControllerB) so that I can setup each controller as needed in a separate class each. Did I miss something on how to avoid this split? Thanks for keeping me posted if so.

uglyog
2019-07-30 08:15
Unfortunately the consumer annotation is applied to the class level so there would be no way to know which pact applies to which test. Is this for a spring boot app?

sabil.beladri
2019-07-30 08:26
yes, it's for a spring boot microservice I'm fine with doing this split for consumer annotation, too bad for the graphs displayed by the broker, since we'll see 2 different providers in this case It would be great to be able multiple controllers within a same class, each pointing to a distinct state. Or not, it may turn into a mess as well. Anyway, as it is, coupling RestPactRunner along with mockMvc and a controller helps us a lot in running solid provider validations, so I can live with that minor issue. Thanks for clarifying this!

william.robson
2019-07-30 09:50
has joined #pact-jvm

uglyog
2019-07-30 23:31
You can raise an issue at the github project to get the consumer annotation applied at the method level

deshdeepdivakar
2019-07-31 03:34
thanks @uglyog for `default` Provider state I don't really need to inject state right?

deshdeepdivakar
2019-07-31 03:38
I am still getting the error `org.junit.platform.commons.util.PreconditionViolationException: No supporting TestTemplateInvocationContextProvider provided an invocation context`

deshdeepdivakar
2019-07-31 03:39
@PactFolder("src/test/target/pacts")

deshdeepdivakar
2019-07-31 03:39
pacts is all there and Provider state is `default`

uglyog
2019-07-31 03:40
Check the provider name against the @Provider annotation

deshdeepdivakar
2019-07-31 03:44
Awesome, thanks! it wasn't matching now good. :raised_hands:

deshdeepdivakar
2019-07-31 03:45
do you reckon this is also due to some miss configuration?`Request Failed - Connect to localhost:8888 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)`

uglyog
2019-07-31 03:49
Is the springboot app running on port 8888?

deshdeepdivakar
2019-07-31 03:56
No, it isn't on 8888. I just copied over from the example and forgot to change. Appreciate all the help!!

deshdeepdivakar
2019-07-31 04:02
I am loving http://Pact.io it's so good :heart:

gerwin.vaatstra
2019-08-01 11:44
I know there is minArrayLike where you can have multiple arrays matching, but it looks for an array that matches. Is there an equivalent for objects? My issue: I have an array with multiple objects (in my case activities in a ride). Not all activities have the same fields. I'll post an constructed simplified example in the Thread (not to spam the room). What I notice is that the generated pact has matchers like: "$[*].activities[2].fieldname" where I would like it to check that there is at least 1 activity object present with the validation on the fields

gerwin.vaatstra
2019-08-01 11:45
Example response: [ { "idNumber": 123, "activityList": [ { "city": "ABC", "actType": "DEPART", "actId": 1, "actDateTime": "2019-08-01T12:00:00Z", "equipment": [ { "field1": "AA", "field2": 1, } ] }, { "city": "NNN", "actType": "PASS", "actId": 2 }, { "city": "XYZ", "actType": "ARRIVE", "actId": 3, "actDateTime": "2019-08-01T12:00:00Z" } ] } ]

gerwin.vaatstra
2019-08-01 11:45
Expected structure: DslPart ritten = newJsonArrayMinLike(1, lambdaDslJsonArray -> { lambdaDslJsonArray.object(RIDE -> { RIDE.numberType("idNumber", 123); RIDE.array("activityList", ACTIVITIES -> { ACTIVITIES.object(ACTIVITY -> { ACTIVITY.stringType("city", "ABC"); ACTIVITY.stringValue("actType", "DEPART"); ACTIVITY.numberValue("actId", 1); ACTIVITY.timestamp("actDateTime", "yyyy-MM-dd'T'HH:mm:ss'Z'", planDatumTijd); ACTIVITY.minArrayLike("equipment", 1, EQUIP -> { EQUIP.stringType("field1", "AO"); EQUIP.numberType("field2", 5); }); }); ACTIVITIES.object(ACTIVITY -> { ACTIVITY.stringType("city", "NNN"); ACTIVITY.stringValue("actType", "DEPART"); ACTIVITY.numberValue("actId", 2); }); ACTIVITIES.object(ACTIVITY -> { ACTIVITY.stringType("city", "XYZ"); ACTIVITY.stringValue("actType", "ARRIVE"); ACTIVITY.numberValue("actId", 3); ACTIVITY.timestamp("actDateTime", "yyyy-MM-dd'T'HH:mm:ss'Z'", planDatumTijd); }); }); }); }).build();

gerwin.vaatstra
2019-08-01 11:56
So what I'd need is 1 array with activities with a variable amount of objects with variable fields :wink:

uglyog
2019-08-01 22:26
Pact doesn?t support polymorphism. What you?ll need to do is have different tests that have a set example and define your contracts based on that

sundakr1
2019-08-02 00:17
has joined #pact-jvm

kapoorvishal23
2019-08-02 12:14
has joined #pact-jvm

pavani.polakala
2019-08-02 21:47
@uglyog I have a general doubt. I have written consumer test cases on Android and generated a pact file. Is provider responsible to write corresponding test cases to verify consumer tests? Does provider test these APIs against actual server and check if the actual response is same as that of consumer expected response?

johngluckjunk
2019-08-03 00:12
has joined #pact-jvm

uglyog
2019-08-03 02:45
Yes, exactly that

chaoscifer
2019-08-03 21:27
has joined #pact-jvm

sundakr1
2019-08-06 09:04
Folks, I have a unique use case to solve and hope this channel can help. We are transitioning to a Microservices architecture. Some of the newer apps are written in Spring-Jaxrs and teams are planning to use Springboot-Jaxrs. Teams that have adopted old Spring-Jaxrs based frameworks want to have pact tested against their provider APIs. The issue, in this case, is I will have to deploy before executing the pact tests. My question is: Is there an alternative? Or should I ask the teams to migrate to Spring boot?

deshdeepdivakar
2019-08-06 11:48
hi @here do we have some examples for `Json-rpc` ?

pbarrientos
2019-08-06 15:17
has joined #pact-jvm

sabil.beladri
2019-08-06 16:14
I finally managed to find a moment to create this issue: https://github.com/DiUS/pact-jvm/issues/919 please let me know in case this is not clear

pavani.polakala
2019-08-07 04:10
@uglyog I'm using regular expressions to match the header values. Following is my code `builder.uponReceiving(DESCRIPTION)` ` .path(PATH)` ` .method(POST_METHOD)` ` .willRespondWith()` ` .status(STATUS_CODE_CREATED)` ` .matchHeader(HEADER_1, "[0-9A-Za-z]+")` ` .toPact();` Matching rule is generate as below in the pact file: `"matchingRules": {` ` "header": {` ` "HEADER_1": {` ` "matchers": [` ` {` ` "match": "regex",` ` "regex": "[0-9A-Za-z]+"` ` }` ` ],` ` "combine": "AND"` ` }` ` }` However, when the provider runs this test case, it is not checking whether the header value is matching the pattern. It is comparing the header value with randomly generated value. How to solve this issue?

deshdeepdivakar
2019-08-07 07:38
hi @uglyog can you please suggest if this isn't look right for `json-rpc`

gerwin.vaatstra
2019-08-07 08:33
I was curious so did searched an example. I did find this matcher in the repo. You could try if that notation works https://github.com/DiUS/pact-jvm/blob/4106422f4b5ade4a63c5662818defc0a71f99473/pact-specification-test/src/main/resources/v2/response/headers/matches%20with%20regex.json

uglyog
2019-08-07 10:07
There is nothing wrong with the matcher. What version are you using?

pavani.polakala
2019-08-07 14:05
I'm using this version - 3.6.11

pavani.polakala
2019-08-07 14:23
@gerwin.vaatstra This json is generated by pact. I can't modify it. I can only specify the regex in my test case.

pavani.polakala
2019-08-07 16:57
@uglyog I tried setting the response body as given below - body(PactDslJsonRootValue.stringType()) But I'm getting expectation not met error : Expected \"\\\"string\\\"\" but got \"3eeeeed3d9ab0bba888c922ea7a3741964039e50\" at $

pavani.polakala
2019-08-07 17:16
I'm wondering if I should write some code on provider side to validate the regex?

pavani.polakala
2019-08-07 19:04
Looks like the matching rules are dropped by provider. The interaction in pact broker is not showing matching rules.

amber.race
2019-08-07 21:47
has joined #pact-jvm

brent.foley
2019-08-07 22:43
has joined #pact-jvm

brent.foley
2019-08-07 23:09
hello. I have basic setup for pact working in java. I am using annotations very similar to this post: https://github.com/DiUS/pact-jvm/issues/815 I have verification results being posted back to broker, but it only works if *all* the tests pass. If I run the tests and have a failure, the results aren't sent to broker. Any idea why that is?

uglyog
2019-08-07 23:26
How are you running the verification on the provider? Also, enabling debug level logs will help.

chaoscifer
2019-08-08 00:36
Hello! Please, for JUnit5 if a put a relative path it would work if this path is outside my test resources? I'm setting up exactly as the examples from gh (but with Kotlin and Gradle 5.5.1) with no success I'm stuck at "No service providers are configured". I think I'm doing something wrong with my sourceSet. Indeed, I would like to read more documentation about JUnit5 pact-jvm-provider notations. Thanks!

uglyog
2019-08-08 00:53
Junit @Folder annotation loads via the classpath, so the resources directory is the easiest to use. But if you add your directories to the classpath that should work

pavani.polakala
2019-08-08 01:09
I'm not sure how it is being done since it is being handled by some one else in our team. I will get back to you on that. But I wanted to know if provider should handle regex explicitly?

uglyog
2019-08-08 01:13
No, the regex should be evaluated by what ever us running the provider validation

chaoscifer
2019-08-08 01:15
Thanks for your reply. Do you think that something like this would work? (assuming that my pact files within src/contractTest/resources/pacts) sourceSets { contractTest{ compileClasspath += blabla runtimeClasspath += blabla resources { srcDir "src/contractTest/resources" } } }

uglyog
2019-08-08 01:17
If it's in the resources already, you don't need that

pavani.polakala
2019-08-08 02:00
Ok. What could be causing this issue? Provider is not considering the regex. It is matching the randomly generated value with actual value.

pavani.polakala
2019-08-08 02:00
Do you have any working example of matchers in java?

uglyog
2019-08-08 02:04
If you use the Gradle, Maven or JUnit to run the verification, the matchers should work.

antstorm
2019-08-08 08:38
has joined #pact-jvm

oswald.quek
2019-08-08 14:59
.

brent.foley
2019-08-08 16:03
Hello, I am not sure if this is a defect or me... My test setup looks like this. If the tests all pass then everything works as you'd expect. Verification results are sent to my pact broker. However, if a test fails, no results get sent to broker. If I remove @SpringBootTest from the class annotations, the failures DO get sent to broker. But by removing that annotation, the @AutoWiring no longer works. So I appear to be stuck

brent.foley
2019-08-08 16:07
I followed the pact-workshop-jvm to get to where I'm at

brent.foley
2019-08-08 16:08
I think my case is just slightly more complex since I'm Autowiring components in my test class and the workshop did not do that

anupamknw
2019-08-08 18:46
has joined #pact-jvm

jgluck
2019-08-08 19:51
Before I tell the developer they have made a mistake, I want to confirm something. I am using SpringBoot 1.5 Java 8 Pact 3.6.11 (because we can't use beta versions of software here) JUnit4 Pact Broker I am able to get a 200 from my provider, but I am having trouble with the Content-Type My provider class looks like so ```@RunWith(SpringRestPactRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @PactBroker( host = "localhost", port = "9292") @Provider("decision-input-repository") public class SomeTest { @LocalServerPort private int port; @TestTarget public final Target target = new SpringBootHttpTarget(); @Autowired private DirController dirController; @MockBean private DirServiceImpl dirServiceImpl; @State("profile upsert") public void decisionInputProfilePost() { } }``` My contract is ``` { "status": 200, "headers": { "Content-Type": "application/json;charset=UTF-8" }, "body": { <bunch of stuff here> } ``` 1. I am seeing this in the logs ``` 12:30:41.421 [main] DEBUG a.c.d.pact.provider.ProviderClient - Response: {statusCode=200, headers={X-Content-Type-Options=[nosniff], X-XSS-Protection=[1; mode=block], Cache-Control=[no-cache, no-store, max-age=0, must-revalidate], Pragma=[no-cache], Expires=[0], X-Frame-Options=[DENY], Content-Length=[0], Date=[Thu, 08 Aug 2019 19:30:41 GMT]}, contentType=application/json; charset=UTF-8, data=} ``` I saw a response to some saying they had misspelled the header but it's not clear to me that it's possible to do that in Spring Boot assuming someone is using the standard annotations and it appears the developer is doing things corrects. 2. Also, I don't know if I'm doing something wrong but I haven't been able to remove the JSON Content-Type. If I don't include it in my `.willRespondWith().headers()`, the expectation still appears when I generate the pact, so it appears Pact always includes this. Is that correct?

jgluck
2019-08-08 22:12
I have just been able to confirm that the service in standalone returns the headers ```curl -i -X POST http://localhost:8080/api/decision-input-repository/v1/profile -H "Content-Type: application/json" -d '{<bunch of stuff here>}' HTTP/1.1 200 X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Frame-Options: DENY Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked Date: Thu, 08 Aug 2019 22:09:49 GMT```

jgluck
2019-08-08 22:23
Is this a defect?

borsuk.artem034
2019-08-09 08:00
Hello, does pact-jvm-consumer-java8(lambdaDSL) support messaging(MessagePactBuilder)?

pavani.polakala
2019-08-09 13:42
@uglyog I found out that provider is ignoring the matching rules. This is what I found in logs - `Ignoring unsupported matching rules {"Th_jwt"=>{"matchers"=>[{"match"=>"regex", "regex"=>".*"}], "combine"=>"AND"}} for path ['header']` What could be causing this issue?

pavani.polakala
2019-08-09 15:31
It's working after I changed consumer version to V2. Looks like Ruby implementation on provider supports only v2.

jgluck
2019-08-09 22:40
FYI, I have half figured this out. As it turns out, my body has field which takes a value that is JSON, only not exactly. I need to work on formatting this so that it will go into and come out of the database. I'll let you know if I discover any problems

uglyog
2019-08-10 01:57
Does seem like a defect. Please raise an issue for this.

uglyog
2019-08-10 02:04
`contentType` is incorrect, it has to have a hyphen like `content-type`. Case doesn't matter. So you're saying is that the content type header is correct in the Pact file, but it is getting translated during the verification? But the actual service is returning the correct header?

uglyog
2019-08-10 02:06
I'll be surprised if this is an issue with Pact-JVM, because everyone would be having this issue. Can you try version 3.5.25 and see if you have the same issue?

uglyog
2019-08-10 02:08
You should be able to use it in the same way

borsuk.artem034
2019-08-11 11:02
```@Pact(provider = "pro", consumer = "con") public MessagePact createPact(MessagePactBuilder builder) { return builder .expectsToReceive("state") .withMetadata(metadata) .withContent(newJsonBody((s) -> { s.stringValue("foo", "Foo"); s.stringValue("bar", "Bar"); })) .toPact(); }``` Method .withContent expect au.com.dius.pact.consumer.dsl.DslPart not the lambda DSL

uglyog
2019-08-11 23:00
Call `.build()` to return the correct class

borsuk.artem034
2019-08-12 07:04
Thanks you for help, it's works,

jgluck
2019-08-12 15:54
I think this has to do with the embedded JSON. I think this is my problem

neelofer.tamboli
2019-08-13 09:21
has joined #pact-jvm

neelofer.tamboli
2019-08-13 09:24
Hi. We have a provider with 2 consumers. Both consumers use different APIs of the provider. We would like to keep the provider side tests written in separate classes for modularity purposes. Contract test class: ```@RunWith(SpringRestPactRunner.class) @ContextConfiguration(classes = { ProviderApplication.class }) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @PactBroker(failIfNoPactsFound = false) public abstract class ContractTest { }``` Provider side, Consumer 1: ```@Provider("provider-one") @Category({ ContractTest.class }) @IgnoreNoPactsToVerify public class ProviderConsumer1Test extends ContractTest { @LocalServerPort public int port; @TestTarget public final Target target = new SpringBootHttpTarget(); @Before public void setup() { when(...).thenReturn(Boolean.TRUE); } @TargetRequestFilter public void requestFilter(HttpUriRequest request) { ..... } } ``` And similarly a provider side test for Consumer 2. We are not providing any `state` on the Provider test class because we don't have particular mocking for the states which we have not already covered in the setup. My questions: 1. Would this be a correct approach? 2. When we run provider side test, same state from each consumer is verified against both provider test classes. How can we change that? We want each provider class to verify pacts of only one specific consumer each. Thank you.

borsuk.artem034
2019-08-13 10:08
Hello, can I somehow specify the list of objects through the "eachLike" or someting else? I have many similar objects like: ``` "Attributes":[ { "Type":"type_value", "name":"name_value", "originalName":"name_value" }, { "Type":"type_value", "name":"name_value", "originalName":"name_value" }, .....many same objects ] ``` Trying to use: ``` ...array("Attributes", Attributes -> { Attributes.eachLike(Attributes.object((attribute) -> { attribute.stringMatcher("Type", "type_value"); } )); }); ```

guidopio.mariotti10_d
2019-08-13 13:21
Hi everyone, I?m currently working in integrating pact into a couple of our kotlin microservices and I created a couple of methods to have a more kotlin friendly dsl. I?d like to contribute it back to pact-jvm, is this something that the pact team can be interested in?

uglyog
2019-08-13 23:27
To be honest, the correct approach is what works for you. You can filter the pacts that are verified by the consumer. See https://github.com/DiUS/pact-jvm/blob/master/provider/pact-jvm-provider-junit/README.md#filtering-by-consumer

uglyog
2019-08-13 23:29
`eachLike` works on an array (or list) by specifying that each object in the array must match the provided template.

uglyog
2019-08-13 23:29
Instead of `...array("Attributes", ` you must use the `eashLike` here

uglyog
2019-08-13 23:30
:100:! There are lots of people who have been waiting for a nice Kotlin DSL

guidopio.mariotti10_d
2019-08-14 06:14
cool, I?ll try to open a PR in the next couple of weeks so that we can collect some feedback on it

neelofer.tamboli
2019-08-14 10:08
Thank you

jgluck
2019-08-14 20:12
Is there a sample pom.xml for publishing results to the broker somewhere? In particular, I'm using version 3.6.11 so I'm not sure what syntax is supported in that version. I haven't been able to find a clear single file example and I am confused. They way my implementation works now, I am always asked for a stateChangeURL, but I'm not using a stateChangeURL, so I'm not sure what to provide there.

antonello
2019-08-14 20:20
What are you trying to publish? Pacts or verification results?

antonello
2019-08-14 20:22
Sorry, I should?ve read your message more carefully :slightly_smiling_face:

antonello
2019-08-14 20:27
``` <profile> <id>pact-provider-tests</id> <activation> <activeByDefault>false</activeByDefault> </activation> <properties> <pact.include.categories>PactProviderTests</pact.include.categories> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <argLine>${companyName.surefireArgLine} ${jacoco.surefireArgLine}</argLine> <redirectTestOutputToFile>true</redirectTestOutputToFile> <testSourceDirectory>src/test/java</testSourceDirectory> <groups>${pact.include.categories}</groups> <systemPropertyVariables> <pact.provider.version>${pact.pacticipantVersion}</pact.provider.version> <pact.verifier.publishResults>false</pact.verifier.publishResults> <pact.provider.version.trimSnapshot>true</pact.provider.version.trimSnapshot> </systemPropertyVariables> </configuration> </plugin> </plugins> </build> </profile> ```

antonello
2019-08-14 20:28
In this case we have a profile and some filtering done based on junit `@Category`.

antonello
2019-08-14 20:28
you may not want to do that

antonello
2019-08-14 20:34
In short: >For pacts that are loaded from a Pact Broker, the results of running the verification can be published back to the broker against the URL for the pact. You will be able to then see the result on the Pact Broker home screen. > >To turn on the verification publishing, set the system property pact.verifier.publishResults to true in the pact maven plugin, not surefire, configuration. https://github.com/DiUS/pact-jvm/tree/v3.6.x/pact-jvm-provider-maven#publishing-verification-results-to-a-pact-broker-version-354

johngluckjunk
2019-08-15 01:07
Thanks @antonello I'll give that a go when I get some time in a few days

chaoscifer
2019-08-19 14:13
Hello all! Please, I'm trying to run a gradle task with my provider tests (using JUnit). The task runs successfully, but without invoke the tests from my class. I'm using as reference documentation in here: https://github.com/DiUS/pact-jvm/tree/master/provider/pact-jvm-provider-junit And here: https://github.com/DiUS/pact-jvm/tree/master/provider/pact-jvm-provider-junit/src/test Please, am I missing some config or annotation?

uglyog
2019-08-19 20:36
Are you able to post your test?

chaoscifer
2019-08-19 23:27
@uglyog, I just figured out a few minutes ago. The issue was on the following lines on my build.gradle: useJUnitPlatform{ includeEngines 'spek2', 'junit-jupiter' } Thanks!

fil.tmb
2019-08-20 11:02
has joined #pact-jvm

jgluck
2019-08-20 15:32
This worked @antonello. Thanks for the advice

antonello
2019-08-20 15:33
My pleasure!

getsreerag22
2019-08-21 04:25
has joined #pact-jvm

matchehot
2019-08-21 18:29
has joined #pact-jvm

matchehot
2019-08-21 18:29
Hi, has anyone used jvm XmlBodyMatcher to match response body? Looking for example

dglaubman600
2019-08-22 02:27
has joined #pact-jvm

james.hattersley-dyke
2019-08-22 08:13
Morning all, I discovered yesterday the pact-jvm-provider-junit way of doing things... previously I'd just been using pact-jvm-provider-gradle and just calling `pactVerify` what's the advantage / disadvantage of doing it as a junit test? On first glance, it seems like I'm going to have to fully run my CI pipeline to get the verifications to happen whereas I can set up a single CI build job to just call `pactVerify ` using the gradle provider? Is there a recommended approach or are both valid?

abubics
2019-08-22 08:16
@james.hattersley-dyke

james.hattersley-dyke
2019-08-22 08:20
cheers, I've never really needed to do any mocking in the versifications I've done to date so not needed junit etc. This week was the first time we encountered an issue where we needed to start WireMock and then start the Spring app before running `pactVerify`. We tried using the `startAppTask` in the gradle provider but the devs went with the junit provider instead... no issue with that, just wondered if there was a recommended approach? Seems like picking the right tool for the job really?

abubics
2019-08-22 08:26
not really . . . just depends which idiom you prefer to use :slightly_smiling_face:

abubics
2019-08-22 08:26
I like the gradle version, and @uglyog now prefers the junit style

abubics
2019-08-22 08:26
the gradle way, you have to do a bit more setup (with launching the app, and the state change endpoint)

abubics
2019-08-22 08:27
the junit way, more of it is done for you, but you have to use junit :stuck_out_tongue:

james.hattersley-dyke
2019-08-22 08:36
I've been doing a lot with messaging (sqs) systems recently so I've not really needed the JUnit stuff... Might give it a whirl next time...

borsuk.artem034
2019-08-22 09:36
@uglyog sorry for the late answer, had a vacation. But your advice acceptable for json like ``` "Attributes":[ [ "Type":"type_value", "name":"name_value", "originalName":"name_value" ], .....many same objects ] ```

borsuk.artem034
2019-08-22 09:38
but I have one array with many similar objects like: ```"Attributes":[ { "Type":"type_value", "name":"name_value", "originalName":"name_value" }, .....many same objects ] ``` maybe you know how i can describe that using "Like" statement?

uglyog
2019-08-22 22:51
Not many people use XML, so I doubt there would be any examples. Maybe you can be the one to contribute the first one :smile:

sundakr1
2019-08-27 03:49
Tried with Jax-rs endpoint server and jaxrsserverfactorybean. I do not require a springboot app after all. Here is sample code built on top of pact-jvm-workshop.

guidopio.mariotti10_d
2019-08-27 09:22
Hi, is there anyone that was able to run a Provider test with Junit 5 and Spring Webflux? I?m trying using `@WebFluxTest` together with `@LocalServerPort` but I?m not sure it is working properly

guidopio.mariotti10_d
2019-08-27 17:50
or, alternatively, can I avoid the pact provider to execute the http request and just execute the request specification myself?

uglyog
2019-08-27 23:23
You can use the Gradle plugin to run the verification of the provider

kashikar.harsh
2019-08-28 05:19
has joined #pact-jvm

kashikar.harsh
2019-08-28 05:19
Hey All

kashikar.harsh
2019-08-28 05:20
I am looking for some help on provider verification that involves mocking a function call that provider is calling

kashikar.harsh
2019-08-28 05:20
the use case is, my provider gets input, does a little bit transformation and writes the data to service bus

kashikar.harsh
2019-08-28 05:21
obviously I do not want the data to be written to service bus every time I run provider verification and looking for a way to mock this scenario

kashikar.harsh
2019-08-28 05:21
any inputs/help is much appreciated

uglyog
2019-08-28 05:35
User a provider test written with JUnit and mock out the collaborator that writes to the message queue

kashikar.harsh
2019-08-28 05:42
not sure if I could quite understood this, mostly I have written pact in node and there the provider verification is just to call a verify method

kashikar.harsh
2019-08-28 05:43
so assuming we do have more control in provider verification with jvm

kashikar.harsh
2019-08-28 05:43
or perhaps it is there is node as well and I may not have explored it

uglyog
2019-08-28 05:44
Should be able to do that pretty easy in node. Maybe ask in the #pact-js channel

kashikar.harsh
2019-08-28 05:50
Sorry for not being clear, I nee to write this time in java only with junit test framework

kashikar.harsh
2019-08-28 05:50
are there any examples of using mock that I can refer to?

uglyog
2019-08-28 05:52
Are you using springboot?

kashikar.harsh
2019-08-28 05:53
yes

uglyog
2019-08-28 05:57
You can use springboot test annotations and @MockObject to mock out the collaborator. See this for a basic springboot provider test: https://github.com/DiUS/pact-jvm/blob/master/provider/pact-jvm-provider-spring/src/test/groovy/au/com/dius/pact/provider/spring/SpringRunnerWithBeanThatMustBeClosedProperlyTest.groovy

uglyog
2019-08-28 05:58
Sorry, I think the annotation is @MockBean

kashikar.harsh
2019-08-28 06:03
Thanks @uglyog will check this out

guidopio.mariotti10_d
2019-08-28 07:54
I?m actually using the gradle plugin. What I meant was, can I get the request specification so that I can use the `TestWebClient` configured by the `@WebFluxTest` and avoid having to start the entire application? Or do you have any other suggestion on how to run those tests against a webflux application?

guidopio.mariotti10_d
2019-08-28 07:54
To me, this is more a spring boot problem than a pact one, but I haven?t found anything for spring so I?m hoping I can work around this with pact

uglyog
2019-08-28 09:39
I have no idea about webflux, but if @WebFluxTest works similar to the springboot test one, you should be able to use it

guidopio.mariotti10_d
2019-08-28 09:45
unfortunately not, `@WebFluxTest` doesn?t start a server. However, I think I figured out a solution using `@SpringBootTest`. If I find some time, I?ll try to contribute something that works with `@WebFluxTest`

kashikar.harsh
2019-08-28 12:56
another dump question, how do I build the PactDslJsonBody if the method is expecting 3 params , param 1 - byte array, param 2 - This is set to null and param 3 - a custom class object

kashikar.harsh
2019-08-28 13:05
asking because I didn't find a specific byte data type for array

guidopio.mariotti10_d
2019-08-28 13:11
however, using the gradle `pactVerify`, it doesn?t run the `@SpringBootTest` like when you test the messaging part with `verificationType=ANNOTATED_METHOD`. Any workaround this?

uglyog
2019-08-28 22:50
Which method are you referring to?

uglyog
2019-08-28 22:52
`pactVerify` runs the verifications itself, using a running application

kashikar.harsh
2019-08-29 05:28
my provider method that I want to register my pact against

uglyog
2019-08-29 05:32
ok, and what does the request look like that is sent to your app?

kashikar.harsh
2019-08-29 05:33
it calls readbytes on a json string and send it

kashikar.harsh
2019-08-29 05:33
this is about message queue based contract

kashikar.harsh
2019-08-29 05:34
so the provider receives this data, massages it and puts it into another service bus

kashikar.harsh
2019-08-29 05:34
need to validate this provider

uglyog
2019-08-29 05:40
ah, and param1 is the byte array of the JSON

uglyog
2019-08-29 05:43
If you can mock out the call to the other service bus, you can assert that the correct JSON was sent. In your test method call your provider method with the 3 parameters and then check that the downstream got the correct message

kashikar.harsh
2019-08-29 05:44
yes

kashikar.harsh
2019-08-29 05:44
I am trying to call the provider method but stuck while sending the params

kashikar.harsh
2019-08-29 05:45
body .object() .nullValue("paramName") .closeObject(); body .object("paramName") .booleanValue("manual", true) .stringValue("actionType","SomeAction") .closeObject();

kashikar.harsh
2019-08-29 05:45
this is how I constructed for the other 2 params one of which accepts null for this specific case and other accepts an object

kashikar.harsh
2019-08-29 05:46
but couldn't find similar method for constructing a byte [] to pass on to the 1st param

uglyog
2019-08-29 05:47
JSON doesn't have a byte array type. Is the parameter data from a string?

uglyog
2019-08-29 05:47
Or is it an array of numbers?

kashikar.harsh
2019-08-29 05:49
my bad it is json bundled as string and we are using getBytes method on string

kashikar.harsh
2019-08-29 05:52
String alert = StreamUtils.copyToString(is, Charset.forName("UTF-8")) - this is snippet from unit test

kashikar.harsh
2019-08-29 05:52
is - this is pointer to a json file

kashikar.harsh
2019-08-29 05:52
alert will load json from file and finally will be passed on to provider method as alert.getBytes()

uglyog
2019-08-29 05:58
The verification tests work by calling a method and checking the returned value matches the pact. So you need to write your test in a way that you pass the data as required to your method, then get what was passed to the service bus and return that.


uglyog
2019-08-29 05:59
PactDslJsonBody will be used by the consumer test of whatever is processing the message off the service bus

kashikar.harsh
2019-08-29 06:07
provider method is not returning anything here, it is just dumping that into another service bus

kashikar.harsh
2019-08-29 06:07
so for consumer tests, I need not to build PactDslJsonBody is what you are saying?

kashikar.harsh
2019-08-29 06:11
also at this point of time I am trying to write consumer tests,, but the examples are all using PactDslJsonBody

uglyog
2019-08-29 06:11
The consumer test (whatever reads the message from the service bus) will setup the pact via a test, and need to define what the format of the message is.

uglyog
2019-08-29 06:12
Your provider (the what writes to the service bus) needs to use a test like the example above. The test method will have to return the contents of the message.

kashikar.harsh
2019-08-29 06:13
understood, or in case if it is not returning anything, I can atleast ensure it doesn't throw any exception and mock the writing to service bus part

kashikar.harsh
2019-08-29 06:14
Developer may not welcome any changes about returning the value now :disappointed:

kashikar.harsh
2019-08-29 06:14
is there a sample consumer test that doesn't use PactDslJsonBody

uglyog
2019-08-29 06:15
There are a few that use JSON as a string value

uglyog
2019-08-29 06:15
Nothing special, they just provide the string contents

kashikar.harsh
2019-08-29 06:15
ok, let me try

kashikar.harsh
2019-08-29 06:16
thanks a lot @uglyog, will keep you posted on how this goes

guidopio.mariotti10_d
2019-08-29 07:48
yeah, I thought it was making easier to run the tests using junit. At the end, I decided to go with the junit5 tags and the `@PactBroker` annotation

joao
2019-08-29 13:35
has joined #pact-jvm

priyank.shah217
2019-08-30 05:49
has joined #pact-jvm

mui_ume
2019-08-30 08:11
my pom.xml has this ```<plugin> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>4.0.0</version> <configuration> <serviceProviders> <serviceProvider> <name>Platform Services</name> <protocol>http</protocol> <host>localhost</host> <port>9319</port> <path>/</path> <pactFileDirectory>src/test/resources/pacts</pactFileDirectory> </serviceProvider> </serviceProviders>```

mui_ume
2019-08-30 08:12
is this the mock pact broker?

kian.leong
2019-08-30 08:16
has joined #pact-jvm

ruben.perezg
2019-08-30 09:07
Hi! :slightly_smiling_face: I have been trying to take a look at the code of `pact-jvm`, to see if I was able to create a PR that would solve this issue: https://github.com/DiUS/pact-jvm/issues/823 I have not found where is the code that handles that from the `pact-jvm`, I would like to see if I could try to implement that somehow (if I can figure out how xD), rather than having to use the workaround proposed in the issue while it's not implemented. Could anyone point me in the right direction, so I can see if I can do something to implement this, or to finally go for trying the workarounds proposed? As far as I see it, it looks like I need to apply those tags to be able to use the `can-i-deploy` tool properly.

brent.foley
2019-08-30 18:41
Hello. Are there examples of pact being used with TestNG framework or is it only supported in junit for java?

nyarasha
2019-08-30 18:54
has joined #pact-jvm

uglyog
2019-08-30 23:29
I haven't seen any example with TestNG.

priyank.shah217
2019-08-31 11:56
I am new to PACT, Have a question: In my consumer side, i am able to generate pact file with json array (2 entries) with some fields. The json contract uploaded to pact-broker successfully. But while running this file against producer, which basically ingest some random data on those json fields (entries may vary, and data could be any random). due to this eventually my contract test failed. returns a response which has status code 200 (OK) has a matching body (FAILED) So now question is i am more interested into json schema, not in content matching. Is there any way to just focus on those part using pact.

priyank.shah217
2019-08-31 12:02
Do i need to set state from provider side in order to get matched response ? (using directly ingesting data into repository)?

priyank.shah217
2019-09-01 04:54
I really done my weekend exercise successfully by implementing pact for one of pet project. https://github.com/priyankshah217/ContractTestingExample.git Nice documentation @bethskurrie @uglyog and whole pact team...

kashikar.harsh
2019-09-01 11:14
Hey all

kashikar.harsh
2019-09-01 11:14
Is there an example of publishing pacts to pact broker using java clients?


kashikar.harsh
2019-09-01 13:52
Thanks @priyank.shah217, couldn't quite locate where you are publishing contracts to broker

kashikar.harsh
2019-09-01 13:52
can you please help me which file I should be referring to

priyank.shah217
2019-09-01 14:28
Refer pom.xml of consumer

kashikar.harsh
2019-09-01 14:42
Thanks, got it

kashikar.harsh
2019-09-01 14:43
Got confused as this is done via mvn plugin, was searching for java code to publish :disappointed:

priyank.shah217
2019-09-03 09:47
i have a question, I am using pact-broker to share contracts.. just wanted to know https://github.com/DiUS/pact-jvm/blob/master/provider/pact-jvm-provider-maven/README.md#2-define-the-pacts-between-your-consumers-and-providers What should be given ?PactUrl? in consumer section?

priyank.shah217
2019-09-03 09:48
here example given for <pactFile>.. what to give if i m sharing contracts over broker?


emils.solmanis
2019-09-03 13:07
has joined #pact-jvm

emils.solmanis
2019-09-03 13:10
hi all, I'm trying to run the provider verifier via Lein and it segfaults, are there particular supported versions of JRE I need, or..? I've tried 8, 11, and 12 to no avail so far

emils.solmanis
2019-09-03 13:13
sorry, it's OpenJDK specifically, and lein 2.9.1

emils.solmanis
2019-09-03 13:29
seems to be Jansi related somehow, can't find anything in open issues ``` Stack: [0x00007f3838765000,0x00007f3838866000], sp=0x00007f3838856bb0, free space=966k Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code) V [libjvm.so+0x8dab2c] C [libjansi-64-5995465925194073194.so+0x1c2a] Java_org_fusesource_jansi_internal_CLibrary_init+0x10a Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) j org.fusesource.jansi.internal.CLibrary.init()V+0 j org.fusesource.jansi.internal.CLibrary.<clinit>()V+21 v ~StubRoutines::call_stub j org.fusesource.jansi.AnsiConsole.wrapOutputStream(Ljava/io/OutputStream;)Ljava/io/OutputStream;+61 j org.fusesource.jansi.AnsiConsole.<clinit>()V+13 v ~StubRoutines::call_stub j au.com.dius.pact.provider.reporters.AnsiConsoleReporter.verifyConsumerFromUrl(Lau/com/dius/pact/core/model/UrlPactSource;Lau/com/dius/pact/provider/IConsumerInfo;)V+12 ```

oswald.quek
2019-09-03 16:05
hello. i'm running a provider test, https://github.com/alphagov/pay-ledger/blob/master/src/test/java/uk/gov/pay/ledger/pact/TransactionsApiContractTest.java. i've set the relevant environment variables:

oswald.quek
2019-09-03 16:05
but when running the test (from intellij), no results are published...

oswald.quek
2019-09-03 16:07
i've put breakpoints at places in the pact classes where the PACT_VERIFIER_PUBLISH_RESULTS env var is being read (e.g. VerificationReporter.kt, ProviderVerifier.kt, TestResultAccumulator.kt) but those breakpoints aren't being hit and results aren't being published

oswald.quek
2019-09-03 16:07
my test passes but there's absolutely no logging about why something isn't being published.

oswald.quek
2019-09-03 16:08
any brainwaves appreciated!

oswald.quek
2019-09-03 16:08
i'm pretty sure i've seen this working locally before

uglyog
2019-09-03 22:54
If publishing the verification was being skipped, there would be an explicit log output stating that

uglyog
2019-09-03 22:54
Can you set the log level to debug?

oswald.quek
2019-09-04 10:09
@uglyog it might be a pact bug. if I remove the `au.com.dius.pact.provider.junit.loader.PactFilter` annotation from my test I see ```{"level":"WARN","logger":"au.com.dius.pact.provider.DefaultTestResultAccumulator","thread":"main","message":"Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true')","service-name":"ledger-service","@timestamp":"2019-09-04T10:08:02.709+0000"} ``` otherwise I don't see it

uglyog
2019-09-04 10:23
Ok, raise a defect for that, please.

borsuk.artem034
2019-09-04 14:26
Hello, I have different with order of Json attributes in consmer and provider, and don't understand why verification (matching body) on provider side is failed? For examlpe: Consumer LambdaDsl create json like: ``` { "foo" : "fooValue", "bar": "barValue" } ``` On Provider side when "Pact verify" a matching body is failed and require ``` { "bar": "barValue", "foo" : "fooValue" } ```

borsuk.artem034
2019-09-04 14:36
info from debug: all fields are validated and math the values: ``` 17:28:25.498 [main] DEBUG au.com.dius.pact.core.matchers.JsonBodyMatcher - compareValues: Matcher defined for path [$, 0, foo] 17:28:25.499 [main] DEBUG au.com.dius.pact.core.matchers.MatcherExecutor - comparing "fooValue" with regexp fooValue at [$, 0, id] -> true 17:28:25.499 [main] DEBUG au.com.dius.pact.core.matchers.JsonBodyMatcher - compareValues: Matcher defined for path [$, 0, bar] 17:28:25.499 [main] DEBUG au.com.dius.pact.core.matchers.MatcherExecutor - comparing "barValue" with regexp barValue at [$, 0, bar] -> true has a matching body (FAILED) has matching metadata (OK) ```

borsuk.artem034
2019-09-04 14:59
never mind, I miss one of objects and diff show all different between all of objects in json, not only missed object

oswald.quek
2019-09-04 15:55
before I do, I was wondering whether this is expected behaviour. if we're filtering pacts by provider state we can't be confident all the interactions were successful as not all of them were run so how can a verification result be published?

oswald.quek
2019-09-04 15:58
also i noticed that on one repository in my organisation, the interaction between a consumer and provider was spread out over different test classes (that's why they used the `@PactFilter` over different classes). i think this is probably bad practice as there's no way for the pact runner to know if all the interactions were successful or not

oswald.quek
2019-09-04 17:30
oh, i see others have encountered this problem too https://github.com/DiUS/pact-jvm/issues/522

guillermo.castro
2019-09-05 13:42
has joined #pact-jvm

andreas
2019-09-09 07:14
has joined #pact-jvm

sarajcarbajal
2019-09-13 09:40
has joined #pact-jvm

hstene
2019-09-16 13:25
Good afternoon, I have a problem using provider states. So I am trying to create a Person with an ID that I get from the provider DB. The ID is an Integer on the Person class. *Pact-creation* ``` @Test public void getPersonById() { Integer id = 100; RequestResponsePact pact = ConsumerPactBuilder .consumer("consumer").hasPactWith("national-registry") .given("A person exist") .uponReceiving("Get person by id") .path("/v1/person") .method("GET") .queryParameterFromProviderState("id", "${id}", id.toString()) .willRespondWith() .status(HttpStatus.OK.value()) .body(new PactDslJsonBody() .stringType("ssn") .valueFromProviderState("id", "${id}", id) ) .toPact(); MockProviderConfig config = MockProviderConfig.createDefault(); PactVerificationResult result = runConsumerTest(pact, config, (mockServer, context) -> { NationalRegistryClient nationalRegistryClient = new NationalRegistryClient(new NationalRegistryConfig(mockServer.getUrl())); nationalRegistryClient.getPersonById(id.toString()); }); assertEquals(PactVerificationResult.Ok.INSTANCE, result); } ``` *Pact-verification* ``` @State("A person exist") public Map<String, Object> getPersonByIdPact(Map<String, String> params) { Person person = personRepository.add(new Person(null, "12345611111", "", null)); Map<String, Object> map = new HashMap<>(); map.put("id", person.getId()); return map; } ``` *Error message* ``` java.lang.AssertionError: 0 - $.id -> [{mismatch=Expected '1' but received 1, diff=}] ``` *I dont understand why it says ?Expected ?1?? in quoutes? The id field on the Person class is an Integer. I am forced to pass the `id` as a String in `queryParameterFromProviderState` example. I send the id as an int in `valueFromProviderState` example.* What am I doing wrong here?


lauri.vaeaenaenen
2019-09-16 16:08
has joined #pact-jvm

kiranpatel11
2019-09-16 21:10
has joined #pact-jvm

uglyog
2019-09-16 22:20
Let me have a look for you to find out what is converting it to a string

uglyog
2019-09-17 00:11
Ah, the expression `"${id}"` is a string. Can you raise an issue for that?

uglyog
2019-09-17 00:13
I think we would be able to convert the result of the expression based on the type of the example value

uglyog
2019-09-17 00:13
The other option would be to make it explicit in the expression (`"${id}:integer"`)

bart.schotten
2019-09-17 09:17
has joined #pact-jvm

bart.schotten
2019-09-17 09:20
Hi, I've noticed that Pact-JVM generates a matching rule with the type "number". As far as I can see this is not part of the Pact Specification (only "decimal" and "integer"). Is the spec not up-to-date or is this a problem with Pact-JVM? This currently makes it impossible for other Pact implementations to verify some of the pacts that are generated by Pact-JVM.

uglyog
2019-09-17 09:25
Good pickup. That isn't really needed because it would be the same as just using a type matcher.

bart.schotten
2019-09-17 09:25
Yeah, that was my thinking as well

james.hattersley-dyke
2019-09-17 14:54
Hi, does any one have any examples of using the `startProvider` and `stopProvider` hooks in the pact-jvm-provider-gradle? We've got to the point where out task starts the app, but then `pactVerify` doesn't run, because the `bootRun` command of SpringBoot is hogging the process. Has anyone used the methods documented here: https://github.com/DiUS/pact-jvm/tree/v3.6.x/pact-jvm-provider-gradle#starting-and-shutting-down-your-provider

abubics
2019-09-17 22:30
Yes, I usually use that... When I get in to work, I can debug with you maybe :)

abubics
2019-09-17 22:31
The only time I've had issues with it was when I got the trigger text wrong :P

uglyog
2019-09-17 23:03
I've used the Gradle Spawn plugin to do that. The only problem with it is it will not work on Windows

abubics
2019-09-18 00:21
I probably stole this from you, @uglyog :joy: ``` import com.wiredforcode.gradle.spawn.* task startProvider(type: SpawnProcessTask, dependsOn: 'assemble') { def path = "$buildDir/libs" if (new File(path).exists()) { def jarFiles = new FileNameByRegexFinder().getFileNames(path, /<your-app>.*\.jar/) command "java -jar ${jarFiles[0]}" ready 'Application started' } } startProvider.doLast { Thread.sleep(100) } task stopProvider(type: KillProcessTask) { } ```

uglyog
2019-09-18 00:22
:party_parrot: the whole Internet is built on stolen code

james.hattersley-dyke
2019-09-18 08:08
thanks! This looks like it'll work...

james.hattersley-dyke
2019-09-18 08:10
I'm trying to introduce a standardised way of running verification tasks for our Spring Boot apps. Some people are writing Unit tests using Junit because starting the app was too complex, others are using just `pactVerify` from the gradle plugin,

james.hattersley-dyke
2019-09-18 08:10
I think using `gradle pactVerify` is much cleaner

vhbsouza
2019-09-18 20:45
has joined #pact-jvm

abubics
2019-09-18 23:51
I think the jUnit style is actually cleaner, because it keeps everything in the test sourceSet

abubics
2019-09-18 23:52
but I like the gradle style because it's easy to reason about, and gives confidence on the built jar . . . you have to put in extra stuff to keep the pact state change endpoint & related code out of the prod artifact, though

wongso_a
2019-09-19 07:17
has joined #pact-jvm

dianaszaharia
2019-09-19 10:54
has joined #pact-jvm

kiranpatel11
2019-09-22 23:34
sharing with to pact-jvm

tjones
2019-09-23 00:21
has joined #pact-jvm

kristine.jetzke
2019-09-23 18:54
Hi, I?m trying to upgrade my provider tests to Junit5. They are using spring and I was using ``` @TestTarget public final Target target = new SpringBootHttpTarget(); ``` Is there something similar for Junit5 and Spring?

kristine.jetzke
2019-09-23 18:56
Nevermind, got it to work :wink:

kristine.jetzke
2019-09-23 18:56
``` @LocalServerPort private int port; @BeforeEach void before(PactVerificationContext context) { context.setTarget(new HttpTestTarget("localhost", port)); } ```

simonmeulenbeek
2019-09-24 10:13
has joined #pact-jvm

simonmeulenbeek
2019-09-24 10:14
Hey, is there a way to match an JsonArray holding key-value pairs? The keynames are different everytime.

simonmeulenbeek
2019-09-24 10:26
Nvm, i'm having a brainfart i think

sabil.beladri
2019-09-25 11:34
Hi, a couple of doubts related to provider validation: ? is there a way to pass tag value from command line (using maven in my case), when using something as @PactBroker([...] tags = ["Release"]) ? My idea is here to be able to switch from a tag to another depending on the git branch, I tried to get system property propagated there but constant value is needed so I see no easy way. I also tried removing tag there and use a maven systemPropertyVariables pact.provider.tag for this purpose, but it would only default to latest without considering another value there. ? also trying to reuse example from [1], I was not able to split in separate classes different @State methods related to a same provider, all must go along the class holding @Provider. This can lead to long classes. It would be great to know if: a- it's possible and I ignore it b- it's a dumb idea and makes no sense c- it would be a possible improvement (I'd create an issue then) [1]: https://github.com/DiUS/pact-jvm/blob/master/provider/pact-jvm-provider-spring/src/test/java/au/com/dius/pact/provider/spring/BooksPactProviderTest.java

zoeabryant
2019-09-25 15:21
has joined #pact-jvm

uglyog
2019-09-25 23:03
1. Dynamic tag values is a good idea. Can you raise an issue for that? 2. Moving the provider state callbacks to another class makes sense. Raise an issue please :smile:

george.papas
2019-09-26 05:07
has joined #pact-jvm

s1apped
2019-09-26 06:03
has joined #pact-jvm

s1apped
2019-09-26 06:04
Hi I have some problem with junit provider , pactbroker and gradle. I try to set PactBroker properties in gradle like test{ systemProperty 'pactbroker.tags', 'test' systemProperty 'pactbroker.host', 'url' systemProperty 'pact.provider.version', 'version' systemProperty 'pact.verifier.publishResults', 'true' } I'm getting error : Did not find any pact files for provider This works just fine @PactBroker(host = "url", scheme = "http", tags = {"test"}). Am I missing something?


uglyog
2019-09-26 06:33
You need to add the property as an expression: `@PactBroker(host="${pactbroker.host}", port = "80")`

borsuk.artem034
2019-09-26 07:09
try to add annotation @Consumer("service-name")

german.schnyder
2019-09-26 07:38
has joined #pact-jvm

s1apped
2019-09-26 08:17
looks like my problem is that I'm using SpringRestPactRunner so it works little bit different

dianaszaharia
2019-09-26 08:35
I also ran into both of these issues, it would be great to see them resolved. How I worked around them - dynamic tags - implement a custom Junit extension that dynamically sets the sytem property "tags" based on current branch. It also polls the pact broker for pacts tagged for existing branch, so that if none exist it fallbacks to master (or prod). This was needed because if no pacts exist with the provided tag, the test will fail with `No supporting TestTemplateInvocationContextProvider provided an invocation context` - splitting states in different classes - extract states in different interface classes and have the pact test class implement those

nathan.deamer
2019-09-26 09:41
has joined #pact-jvm

zoeabryant
2019-09-26 11:27
does anyone have an example of a fully working consumer side contract test in clojure that I could reference?

zoeabryant
2019-09-26 11:28
I have a contract test that runs without error, but doesn't seem to generate a pact that I can publish.

zoeabryant
2019-09-26 13:35
never mind it was hidden in the target folder :joy:


nyarasha
2019-09-26 18:09
Hey all, so I'm totally new to pact but have been reading lots of example code and tutorials. So far, I have not been able to get my head around how to create a pact file. I have set up a junit test, and have the DSL defined for our request / response interactions, but am unclear on how to connect those into the Mock Server (which mocks out the provider side of things). Where do I configure and run a Mock for the provider? What I've come up with so far runs, but I get a `Connection Refused` error (since nothing is running on the Mock Server port at `http://localhost:8080`?) ``` MockServer mockServer = new MockServer() { @NotNull @Override public String getUrl() { return "http://localhost"; } @Override public int getPort() { return 8080; } [...] }; ```

uglyog
2019-09-26 23:04
The mock server will automatically be setup by the test framework. You don't need to do anything there. What version of JUnit are you using?

nyarasha
2019-09-27 14:46
Hm okay. I'm using JUnit 5 and the JUnit 5 JVM Consumer `au.com.dius:pact-jvm-consumer-junit5_2.12`

kashikar.harsh
2019-09-28 16:41
Hey all, I was trying to use pact jvm library for java/junit to validate scala provider method has anyone tried this before? I am facing some problem with compiling both maven and sbt, somehow maven doesn't honor dependencies defined in sbt file and throws exception

kashikar.harsh
2019-09-28 19:39
Also, I was trying to run provider verification using the SpringRestPactRunner.class for asyn contract test and getting the below error

kashikar.harsh
2019-09-28 19:40
Can I use this class for asyn contract test? If not, how can I run the message contract in spring

kashikar.harsh
2019-09-28 19:48
Or can someone please pont me to spingboot example of asyn message contract test?

uglyog
2019-09-29 00:03
@kashikar.harsh looks like it is failing because the URL for the Pact Broker is null. How have you configured your Maven POM?

kashikar.harsh
2019-09-29 05:59
Hi @uglyog I have setup the url in @PactBroker(host="<pact_broker_url>", port="443", scheme="https", tags = {"latest"}) in my provider verification class

uglyog
2019-09-29 06:01
The Maven plugin is for running the verification with Maven. If you're using a JUnit test, it will just run as part of the Maven test phase.

uglyog
2019-09-29 06:01
So you can just run `mvn verify`

uglyog
2019-09-29 06:02
Oh, sorry. You did.

uglyog
2019-09-29 06:02
Is `<pact_broker_url>` just a placeholder for the actual pact broker URL?

kashikar.harsh
2019-09-29 06:05
yes

kashikar.harsh
2019-09-29 06:06
but actually you were right, after I pass pact broker url as param, it worked

kashikar.harsh
2019-09-29 06:06
@PactBroker host parameter is not being used

kashikar.harsh
2019-09-29 06:09
After providing the above parameter, it fails to invoke provider verification method and gives below error

uglyog
2019-09-29 06:14
If you enable debug level logs, you should be able to see why that method failed

kashikar.harsh
2019-09-29 06:38
sure, checking that

catrionamcgarvey
2019-09-30 08:34
has joined #pact-jvm

kashikar.harsh
2019-09-30 09:52
Hey @uglyog I am still getting the same error "Failed to invoke provider method '<my-method-name>'"

kashikar.harsh
2019-09-30 09:53
public final Target target = new AmqpTarget(); - is this applicable for springboot as well or do I have to use a different target?

kashikar.harsh
2019-09-30 10:17
Ok, moved on with the previous error by providing package name containing list of singletons, now getting a classpath error

borsuk.artem034
2019-09-30 10:21
class have "public" accesor?

kashikar.harsh
2019-09-30 10:28
Yeah


kashikar.harsh
2019-09-30 10:29
this seems to be the issue, will proceed with creating custom class as suggested in https://reflectoring.io/cdc-pact-messages/

borsuk.artem034
2019-09-30 10:35
do you use junit4?

kashikar.harsh
2019-09-30 10:40
yes

kashikar.harsh
2019-09-30 11:05
Even with the custom class getting the same exception, any suggestions?

kashikar.harsh
2019-09-30 14:11
Sorry to spam, but seems if I try to run goal pact:verify, it doesn't run in spring context (I don't see springboot info)

alex.thayn
2019-09-30 20:45
has joined #pact-jvm

uglyog
2019-10-01 00:04
@kashikar.harsh pact:verify goal knows nothing about Spring. You need to run your verification as a JUnit test with the spring test annotations

uglyog
2019-10-01 00:08
Also, if using Maven you need to enable the system classloader. See https://github.com/DiUS/pact-jvm/issues/763#issuecomment-487890115

kashikar.harsh
2019-10-01 14:46
Hey all I am trying to parameterize pact broker credentials by using variable pactBrokerCredentials as stated in doc https://github.com/ITV/scala-ITV/scala-pact | Added by GitHub however getting an error that pactBrokerCredentials cannot be resolved using SBT 0.13.16 and scalapact 2.2.5

s1apped
2019-10-01 18:46
Hi. Is it possible to run Provider spring parameterized tests?

uglyog
2019-10-01 22:14
@david.j.smith one for you

uglyog
2019-10-01 22:15
Are you asking about JUnit5 parameterized tests?

s1apped
2019-10-02 09:35
I'm using spring and junit4. I have a contract with matcher on field which accepts enum. On Provider side I'm using SpringRestPactRunner and would like to test all the options and I thought if it's possible to use parameterized tests.

nayaksurajr
2019-10-02 16:00
has joined #pact-jvm

s1apped
2019-10-02 18:35
@uglyog lets say I would switch to Junit5 is it possible to use parameterized tests?

uglyog
2019-10-02 21:57
I was just asking to find out what you meant by parameterized tests. I wouldn't use Pact to test combinations of data. I would use a Unit test to test that the different values can be handled, and one test with an invalid value. And then I would create 2 Pact tests, one with valid values and one with invalid values.

hande.sagar
2019-10-03 04:29
has joined #pact-jvm

hande.sagar
2019-10-03 04:32
Hi All , currently I am facing one problem , when trying to publish pact contract for rest provider. This is the mvn Command we are using in our Jenkin pipeline: MVN cmd: mvn pact:verify -P contract-tests,no-asciidoc -Dpactbroker.host=http://kube-pact -Dpact.verifier.publishResults=true -Dpact.provider.version=fc7194df2b341fbada3c7c2fa0f1ef96abe5f59d -Dpact.tag=feature/FMPSU-236-pact-for-phase-3-4 This is the Error we are getting: 1 @PactVerification then " Verification Failed - No annotated methods were found for interaction 'A GET request to retrieve package with id 04398eb4-0f57-4056-b2ea-aa45bf5c4bfd.'. You need to provide a method annotated with @PactVerifyProvider("A GET request to retrieve package with id 04398eb4-0f57-4056-b2ea-aa45bf5c4bfd.") that returns the message contents. " 2. We have added @PactVerifyProvider with method verifyPackage then we got another error ?Verification Failed - Failed to invoke provider method 'verifyPackage'?. If any one has some idea about this issue please revert back to me.

uglyog
2019-10-03 04:36
With Maven you need to enable the system classloader. See https://github.com/DiUS/pact-jvm/issues/763#issuecomment-487890115

uglyog
2019-10-03 04:38
Oh, wait, that is for running tests via Maven


anothonyvong
2019-10-03 14:35
has joined #pact-jvm

hande.sagar
2019-10-04 04:44
still I am getting below error

hande.sagar
2019-10-04 04:44
[INFO] Published verification result of 'Failed(results=[{message=Request to provider method failed with an exception, exception=java.lang.RuntimeException: Failed to invoke provider met hod 'verifyPackage', interactionId=201b9024ecac5921bd9fc6bfc38eb3b39e5d8331}, {message=Request to provider method failed with an exception, exception=java.lang.RuntimeException: Failed t o invoke provider method 'verifyPackage', interactionId=efb912814610bebdbd82728382fff3d0bf7ad799}], description=Request to provider method failed with an exception)' for consumer 'Consum er(name=consignment-planner)'

uglyog
2019-10-04 04:49
Your provider method is throwing an exception.

hande.sagar
2019-10-04 04:57
when I run my pact contract using junit , it works fine , only it gives error when try to publish using mvn:pact verify

uglyog
2019-10-04 05:00
You need to enable debug level logging with Maven so you can see what the exception cause is.

uglyog
2019-10-04 05:01
If the JUnit test works, why do you need to use mvn pact:verify?

hande.sagar
2019-10-04 05:15
I need to use this command in my jenkin job to publish result on pact server

uglyog
2019-10-04 05:17
The provider JUnit test will also publish the result

hande.sagar
2019-10-04 06:33
this is the log trace in details

hande.sagar
2019-10-04 06:33
[DEBUG] Response body: {"providerName":"package-supplier","providerApplicationVersion":"2.0.0","success":false,"verificationDate":"2019-10-04T08:32:04+00:00","testResults":[{"interactionId":"201 b9024ecac5921bd9fc6bfc38eb3b39e5d8331","success":false,"mismatches":[],"exceptions":[{"message":"Failed to invoke provider method 'verifyPackage'","exceptionClass":"java.lang.RuntimeException"}] },{"interactionId":"efb912814610bebdbd82728382fff3d0bf7ad799","success":false,"mismatches":[],"exceptions":[{"message":"Failed to invoke provider method 'verifyPackage'","exceptionClass":"java.l ang.RuntimeException"}]}],"_links":{"self":{"title":"Verification result","name":"Verification result 10500 for Pact between consignment-planner (v507915e528fc3e6fb6155c1583eba4220b775045) and p ackage-supplier","href":"http://kube-pact/pacts/provider/package-supplier/consumer/consignment-planner/pact-version/088b7abe4cfc7786fd34f8ac40e17a66960726d6/verification-results/10500"},"pb:pact -version":{"title":"Pact","name":"Pact between consignment-planner (v507915e528fc3e6fb6155c1583eba4220b775045) and package-supplier","href":"http://kube-pact/pacts/provider/package-supplier/cons umer/consignment-planner/version/507915e528fc3e6fb6155c1583eba4220b775045"},"pb:triggered-webhooks":{"title":"Webhooks triggered by the publication of this verification result","href":"http://ku be-pact/pacts/provider/package-supplier/consumer/consignment-planner/pact-version/088b7abe4cfc7786fd34f8ac40e17a66960726d6/verification-results/10500/triggered-webhooks"}}} [INFO] Published verification result of 'Failed(results=[{message=Request to provider method failed with an exception, exception=java.lang.RuntimeException: Failed to invoke provider method 'ver ifyPackage', interactionId=201b9024ecac5921bd9fc6bfc38eb3b39e5d8331}, {message=Request to provider method failed with an exception, exception=java.lang.RuntimeException: Failed to invoke provide r method 'verifyPackage', interactionId=efb912814610bebdbd82728382fff3d0bf7ad799}], description=Request to provider method failed with an exception)' for consumer 'Consumer(name=consignment-plan ner)'

uglyog
2019-10-04 06:41
If you enable this Java system property `pact.showStacktrace`, it may show you the exception

uglyog
2019-10-04 06:41
But what the log is staying, is that Pact Maven plugin invoked your verifyPackage method which threw a runtime exception.

dhiral.kaniya
2019-10-04 16:36
has joined #pact-jvm

audun.halland
2019-10-07 09:40
has joined #pact-jvm

audun.halland
2019-10-07 10:46
Using pact-jvm-provider-spring (and HttpTarget), I want to verify a HTTP pact that expects a `301 Moved Permanently`. But it fails because it gets `200 Ok`, because it looks like the client actually performed the redirect, which it shouldn?t, because I?m allowed to publish a pact that expects any http status code. Any tips?

s1apped
2019-10-07 11:02
Thanks!

audun.halland
2019-10-07 13:07
I have solved it by using `CustomHttpTarget : HttpTarget`, and then in `fun testInteraction(...)` I copied the body from `HttpTarget::testInteraction` and inserted my own `CustomHttpClientFactory` which can create an apache http client the way I want. But it would have been better if I didn?t have to copy a lot of logic. I suggest `fun getHttpClientFactory()` to be an overridable method in `au.com.dius.pact.provider.junit.target.HttpTarget`.

audun.halland
2019-10-07 13:13
The http client I want is `HttpClients.custom().disableRedirectHandling().build()`

audun.halland
2019-10-07 13:15
It would make sense to me if that was how the default client was created. I consider it a bug the way it behaves now..

sabino_lrs
2019-10-07 16:46
has joined #pact-jvm

s1apped
2019-10-08 12:35
Hi. I have an issue with randomly failing tests with 500 Internal Server Error. I'm using junit4 with SpringRunner. The issues seems to be related to @Rule PactProviderRule but can't really pin point it. I tried to switch on Junit5 and it works without any issues. Any ideas?

hstene
2019-10-08 12:47
Why not just switch to JUnit5?

s1apped
2019-10-08 12:58
@hstene due to services being old and having quite a few junit4 tests and possible dependencies conflicts. Junit4 to 5 migration is last option..

thomas.heilbronner
2019-10-08 13:00
you can run junit4 tests in junit5

thomas.heilbronner
2019-10-08 13:00
no need to change your existing tests

thomas.heilbronner
2019-10-08 13:00
new ones can be written in junit 5

thomas.heilbronner
2019-10-08 13:01
in case you want/have to migrate have a look at https://github.com/junit-pioneer/convert-junit4-to-junit5

hstene
2019-10-08 13:02
^This

thomas.heilbronner
2019-10-08 13:03
there is a long pending PR that adds quite some functionality to the code https://github.com/junit-pioneer/convert-junit4-to-junit5/pull/16

thomas.heilbronner
2019-10-08 13:04
I used this one to migrate junit 4 tests to junit5 for some of my projects

uglyog
2019-10-08 22:17
I agree, that is not desired behaviour in the mock server

uglyog
2019-10-08 22:18
can you provide some logs?

wongso_a
2019-10-09 01:24
Hi, any idea when documentation for Pending pacts (https://docs.pact.io/getting_started/pending) be available? I'm keen to know more about it.

uglyog
2019-10-09 01:28
I haven't had a chance to implement that yet, let alone write any documentation. In fact, I still need to work out how it works :smile:

wongso_a
2019-10-09 01:29
Would you be able to give me high level idea what problem Pending Pacts will solve?

uglyog
2019-10-09 01:30
I think the idea is to not break the providers build when a new consumer is added or a WIP feature is added to a consumer


wongso_a
2019-10-09 01:32
Nice! My client would love that feature. Thank you :slightly_smiling_face:

hstene
2019-10-09 04:59
This is a great idea @uglyog! :smile:

uglyog
2019-10-09 05:00
It's all @bethskurrie, I'm just the messenger

hstene
2019-10-09 05:00
Then :tada: to Beth!

thomas.scheuchzer2
2019-10-09 09:39
Hi. I just upgraded one of my Spring-Boot examples to Pact 4 and now the consumer tests fail in a strange way. I get `Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server`

thomas.scheuchzer2
2019-10-09 09:43
I can debug the code down to MockHttpServer line 227 `val bodyContents = exchange.requestBody.readBytes()`. When I evaluate the expression it returns an empty byte array what is fine in a get call. But when steppinng through the code the debugger just disappears on that line without catching any exception and the execution continues with the error in the log. I put the example on gitbug: https://github.com/scheuchzer/cdc-demo-2019-10.git The test consumer project is in the folder weather. Any ideas on what is wrong in my code? It used to work fine with pact 3.6

thomas.scheuchzer2
2019-10-09 14:52
I noticed it is working fine with Java 8 until 3.6.13. 3.6.14 throws java.lang.NoSuchMethodError: kotlin.io.ByteStreamsKt.readBytes(Ljava/io/InputStream;)[B with Java 8. After upgrade to Java 11 the same error as with pact 4.0.0 is thrown

thomas.scheuchzer2
2019-10-09 14:54
btw. 3.6.13 is working fine with Java 11

uglyog
2019-10-09 22:55
@thomas.scheuchzer2 can you raise a github issue for that, please?

ryan.dens
2019-10-10 16:53
has joined #pact-jvm

florian.nagel
2019-10-10 17:13
I have encountered the same exception `java.lang.NoSuchMethodError: kotlin.io.ByteStreamsKt.readBytes(Ljava/io/InputStream;)`. I can't help with the debugging because of time issues, but I'd appreciate updates nonetheless! :smile:

kashikar.harsh
2019-10-11 13:33
Hey All Need some help with springboot pact verification for message contracts

kashikar.harsh
2019-10-11 13:34
If I use runner "PactRunner", it doesn't use spring and runs as normal junit test

kashikar.harsh
2019-10-11 13:34
If I change my runner to "SpringRestPactRunner", it loads with spring, however it complains " Did not find any pact files for provider"

kashikar.harsh
2019-10-11 13:35
I am using pact brokers and have @PactBroker to my provider test class with relevant params like host, port, scheme, tags and hardcoded authentication with @PactBrokerAuth

kashikar.harsh
2019-10-11 13:35
in the debug logs, I do not see any traces of it trying to contact broker

kashikar.harsh
2019-10-11 13:36
Anything I am missing here?

kashikar.harsh
2019-10-11 13:42
I running these tests with mvn verify

ryan.dens
2019-10-11 14:57
Hi! I?m looking to use the pact-jvm maven plugin with pactflow. I?ve successfully published pacts from my consumer to the broker, but the way the HTTP client is configured in `PactProviderMojo` does not seem to allow me to specify the header `Authorization: Bearer <TOKEN>` as required by pactflow. I attempted a workaround using the `createClient` configuration to configure the httpclient to always send the correct authorization header like: ``` <createClient> org.apache.http.impl.client.HttpClients.custom().setDefaultHeaders(java.util.Collections.singletonList(new org.apache.http.message.BasicHeader("Authorization", "Bearer <TOKEN>"))).build() </createClient> ``` but unfortunately the `PactProviderMojo` doesn?t seem to use the `HttpClientFactory` that reads that config to create the http client which accesses the pact broker. Is the community open to a change which would allow the pact-jvm-provider to load pacts from pactflow? The way I imagine implementing it is similar to the gradle plugin, but open to suggestions here of course.

ryan.dens
2019-10-11 15:00
I looked for an open issue on github, but couldn?t find one. If I missed it, let me know!

audun.halland
2019-10-12 00:03
@audun.halland has left the channel

uglyog
2019-10-12 00:44
Hi @kashikar.harsh when switching to the Spring runner, the properties for the proker will be resolved as Spring properties not JVM system properties. Just make sure they are defined in your spring context, using the spring boot config file


kashikar.harsh
2019-10-12 04:08
Thank you @uglyog

kashikar.harsh
2019-10-12 04:08
In this case, can you please guide me how do I pass pactbroker credentials as an argument instead of hard coding them in the properties file?


uglyog
2019-10-12 04:13
But I think the values have to first be in the property file, and then you can override them

kashikar.harsh
2019-10-12 04:14
sure, thank you

kashikar.harsh
2019-10-12 04:49
I tried adding these properties with respective values but it still says did not find any pact files

kashikar.harsh
2019-10-12 04:50
again no traces of it contacting pact broker


uglyog
2019-10-12 05:04
If I run `mvn verify -Dpactbroker.host=http://dius.pact.dius.com.au ....`, I can see it using that value in the logs

uglyog
2019-10-12 05:04
``` 2019-10-12 16:03:32.542 DEBUG 12920 --- [ main] a.c.dius.pact.pactbroker.HalClientBase : Fetching: / 2019-10-12 16:03:33.053 DEBUG 12920 --- [ main] a.c.dius.pact.pactbroker.HalClientBase : Fetching: https://dius.pact.dius.com.au/pacts/provider/spring-boot-maven-provider/latest 2019-10-12 16:03:33.323 DEBUG 12920 --- [ main] a.c.dius.pact.pactbroker.HalClientBase : Fetching: / 2019-10-12 16:03:33.492 DEBUG 12920 --- [ main] a.c.dius.pact.pactbroker.HalClientBase : Fetching: https://dius.pact.dius.com.au/pacts/provider/spring-boot-maven-provider/latest 2019-10-12 16:03:33.560 DEBUG 12920 --- [ main] a.c.d.p.p.junit.loader.PactBrokerLoader : Failed to get provider URL from the pact broker au.com.dius.pact.pactbroker.NotFoundHalResponse: No HAL document found at path 'https://dius.pact.dius.com.au/pacts/provider/spring-boot-maven-provider/latest' ```

kashikar.harsh
2019-10-12 05:13
thanks, using the debug mode, I see now it is contacting pact broker

kashikar.harsh
2019-10-12 05:14
however it generates a url like https://<pact_broker_url>/pacts/provider/<provider_name>/consumer/<consumer_name>/version/1.0.1

kashikar.harsh
2019-10-12 05:14
and then says no pact found for provider

kashikar.harsh
2019-10-12 05:14
But if I access the above url using the same credentials as defined in my application.properties, I see the pact

uglyog
2019-10-12 05:19
Check that your provider name is spelt correctly and has the correct case

kashikar.harsh
2019-10-12 05:20
Yes, I copied the url from debug logs and pasted in browser, it worked all fine

kashikar.harsh
2019-10-12 05:21
provider and consumer names are all lower case, so no casing mismatching involved here

uglyog
2019-10-12 05:22
What version of pact-jvm are you using?

kashikar.harsh
2019-10-12 05:23
4.0.0-beta.5

uglyog
2019-10-12 05:27
Can you use 3.6.14? Looks like there is an issue with that version

uglyog
2019-10-12 05:29
``` <dependency> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-provider-junit_2.12</artifactId> <version>3.6.14</version> </dependency> ```

uglyog
2019-10-12 05:31
BTW, you should not mix major versions (4.0.0-beta.5 and 3.6.13)

kashikar.harsh
2019-10-12 05:31
sure, I just upgraded everything to 4.0.0, let me check

uglyog
2019-10-12 05:37
Actually, upgrading that test project to 4.0.0 works for me

kashikar.harsh
2019-10-12 05:38
unfortunately getting the same error : java.lang.Exception: Did not find any pact files for provider <provider_name>

kashikar.harsh
2019-10-12 05:42
Some findings, it first calls the api to get the latest pact: https://cas-pact-broker.eng.citrite.net/pacts/provider/cas-app-actions/latest

kashikar.harsh
2019-10-12 05:43
this returns list of 3 in pb:pacts

kashikar.harsh
2019-10-12 05:44
sorry it is not list of 3 but just 1

kashikar.harsh
2019-10-12 05:44
but interestingly the provider object in response has name set to "Deprecated"

kashikar.harsh
2019-10-12 05:45
and the actual provider name is appearing in title

uglyog
2019-10-12 05:52
That is the problem, it doesn't match the expected provider name

kashikar.harsh
2019-10-12 05:54
Yep, somebody messed up with the pact version, I just registered pact with incremented version

kashikar.harsh
2019-10-12 05:54
however still it gives the same error

kashikar.harsh
2019-10-12 05:56
"DEPRECATED - please use the pb:provider relation"

kashikar.harsh
2019-10-12 05:57
this is coming in provider name, any idea what is this?

kashikar.harsh
2019-10-12 05:57
I think we are still using the provider property from response of latest which is now deprecated and instead we should use pb:provider property to fetch the pact detaisl

kashikar.harsh
2019-10-12 05:58
makes sense?

uglyog
2019-10-12 05:58
I still don't understand why the provider name has been changed

uglyog
2019-10-12 05:59
What version of the pact-broker are you using? You should see that in the response headers

kashikar.harsh
2019-10-12 06:01
it is not changed,it indicates property provider is deprecated and instead we should be using pb:provider

kashikar.harsh
2019-10-12 06:03
pact broker version: 2.29.0

kashikar.harsh
2019-10-12 06:08
Is this something that I can contribute to?

kashikar.harsh
2019-10-12 06:10
Looks like they will remove non pb relation completely in version 3 of pact broker

uglyog
2019-10-12 06:12
That test project works against my broker, which is 2.38.1. Where is the provider property coming from?

kashikar.harsh
2019-10-12 06:13
As response of this request https://<pactbroker_host>/pacts/provider/cas-app-actions/latest

kashikar.harsh
2019-10-12 06:15
it returns json with these properties self, pb:provider, pb:pacts, provider and pacts

uglyog
2019-10-12 06:18
But the Pact-JVM does not use that relation. It will use `pb:latest-provider-pacts`, and then return all the pacts that are returned

kashikar.harsh
2019-10-12 06:20
I don't see this property in the response of latest api

uglyog
2019-10-12 06:26
Not, what I mean, it will first fetch root (/), then look for the `pb:latest-provider-pacts` relation, and then fetch that. Then fetch the `pacts` relation to get the actual pact. It doesn't use `pb:provider`. You can use the HAL browser to follow the same set of links

kashikar.harsh
2019-10-12 06:28
yes, I can relate this with the logs

uglyog
2019-10-12 06:29
The thing I don't understand is why your broker is returning a pact with the provider name set to that. It means it was published with that name.

kashikar.harsh
2019-10-12 06:31
nope, because I see correct provider name in "pb:provider" propert

kashikar.harsh
2019-10-12 06:31
and the json file I checked also has the correct provider name

kashikar.harsh
2019-10-12 06:33
even in the hal browser I see pb:provider set to correct provider name and not provider

uglyog
2019-10-12 06:34
Then that is not the issue.

kashikar.harsh
2019-10-12 06:36
as you said, it doesn't use pb:provider, which property it uses then?

uglyog
2019-10-12 06:36
When you fetch the JSON from `https://<pact_broker-host>/pacts/provider/cas-app-actions/consumer/sf-action-adapter/version/1.0.3`, what does the provider section have?

uglyog
2019-10-12 06:36
It uses the `pacts` one

kashikar.harsh
2019-10-12 06:37
"provider": { "name": "cas-app-actions" },

uglyog
2019-10-12 06:37
That is correct

kashikar.harsh
2019-10-12 06:37
then we are back to start i.e. Did not find any pact files for provider cas-app-actions

kashikar.harsh
2019-10-12 06:38
what else could be the possible issue?

uglyog
2019-10-12 06:38
Are you able to show the Test class?

kashikar.harsh
2019-10-12 06:38
povider?

kashikar.harsh
2019-10-12 06:38
yes I can

uglyog
2019-10-12 06:38
Yes, the provider test class

kashikar.harsh
2019-10-12 06:39
yep

kashikar.harsh
2019-10-12 06:39
Shall I paste the code here?/

uglyog
2019-10-12 06:42
Sure, or you can use a Gist

uglyog
2019-10-12 06:43
Just beware that this is a public forum

kashikar.harsh
2019-10-12 06:44
no idea what is Gist

kashikar.harsh
2019-10-12 06:45
I will pm you

uglyog
2019-10-12 06:46
It's a Github way of sharing code: https://gist.github.com/

kashikar.harsh
2019-10-12 06:50
PM the source code

uglyog
2019-10-12 06:52
Your test looks ok

kashikar.harsh
2019-10-12 06:53
how to proceed on this?

uglyog
2019-10-12 06:53
Can you try run against our test broker? https://test.pact.dius.com.au: Username: dXfltyFMgNOFZAxr8io9wJ37iUpY42M Password: O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1

uglyog
2019-10-12 06:53
You will need to find a provider name there to use

kashikar.harsh
2019-10-12 06:55
Can I use any provider?

uglyog
2019-10-12 06:56
Sure, it's all test data

kashikar.harsh
2019-10-12 07:00
tried with source_provider_sample provider and it could successfully fetch the pact

uglyog
2019-10-12 07:03
Ok, so it must be something with your broker.

kashikar.harsh
2019-10-12 07:03
so you suggest upgrading pact broker?

uglyog
2019-10-12 07:03
Yeah, upgrading the broker to the latest is always a good idea

kashikar.harsh
2019-10-12 07:03
to 2.38.1 or higher

kashikar.harsh
2019-10-12 07:04
ok, I will check with operations team and let you know

uglyog
2019-10-12 07:04
2.38.1 must be the latest

kashikar.harsh
2019-10-12 07:04
Thank you @uglyog for all your time and efforts, appreciate it

uglyog
2019-10-12 07:05
No prob. If you could provide the pact file from that URL, it would help diagnose why it is being rejected

kashikar.harsh
2019-10-12 08:03
any specific section of pact file?

kashikar.harsh
2019-10-12 08:03
I am afraid I can't share the entire file due to obvious business reasons

wongso_a
2019-10-14 06:57
Hi, is there a way for pact-jvm-provider-maven to run tests with Pact contracts that are tagged with "latest"? When I specify the following: <tags> <tag>latest</tag> <tags> I the the an error saying that there is not Pact found for the provider test. After a bit of debugging I found: [DEBUG] Fetching: http://pactbroker.blah.net/pacts/provider/SomeApi/latest/latest

dianaszaharia
2019-10-14 11:32
Hi! Is there an equivalent for `@IgnoreNoPactsToVerify` for junit 5? I see it's only available in the junit 4 module

kashikar.harsh
2019-10-14 14:56
Hi @uglyog We upgraded the pact broker version to 2.38.1, but are still getting the same result

kashikar.harsh
2019-10-14 14:57
Error: Did not find any pact files...

kashikar.harsh
2019-10-14 14:57
Anything else we can try?

kashikar.harsh
2019-10-14 15:08
I have tried re-registering pact with higher pact version and then running the provider verification, it didn't help

kah.goh
2019-10-14 21:53
has joined #pact-jvm

darragh.grace
2019-10-15 16:01
has joined #pact-jvm

uglyog
2019-10-15 22:57
I have someone else who has the same problem as you. I'm going to see if I can resolve it for them. Hopefully, that will help you as well :smile:

uglyog
2019-10-16 03:02
Their problem was authentication with bearer tokens, which is not the issue you are having. But you could try the latest version 4.0.1

simon.waterhouse
2019-10-16 09:58
has joined #pact-jvm

simon.waterhouse
2019-10-16 10:37
Hi @uglyog I am working with @kashikar.harsh on this. The problem appears in PactRunner.kt. I added some diagnostics to filterPacts at line 128 and found that it was receiving a list of 1 pacts as input and (apparently) returning that 1 pact to caller.

simon.waterhouse
2019-10-16 10:39
However when I looked at the contents of the returned list at line 102 it was empty !!!

simon.waterhouse
2019-10-16 10:41
If I replace the call to filterPacts at line 79 with a call to filterPactsByAnnotation (adding the extra testClass.javaClass parameter) then everything works fine.

simon.waterhouse
2019-10-16 10:42
As a Kotlin novice I am wondering if I am missing something obvious here...is it OK in Kotlin to call an object method (filterPacts) from the constructor?

simon.waterhouse
2019-10-16 10:43
BTW using master branch of pact-jvm sunk a day or 2 back.

hande.sagar
2019-10-16 10:47
If I run junit from eclipse all my pact test cases are passed and also publish results on kube pact server , but I need to do same thing using mvn command . any idea? I tried using command mvn test -DjvmArgs -Dpact.verifier.publishResults=true -X but it gives me some other error and pact test cases failed.

simon.waterhouse
2019-10-16 14:57
Here is the logging enhanced PactRunner,kt and a snippet from the log showing it losing the pact: https://gist.github.com/siwater/5b00fadb788f46200c3f31aac96676e2

simon.waterhouse
2019-10-16 15:08
And here is a working PactRunner.kt and a snippet from the log showing the pact is no longer lost: https://gist.github.com/siwater/4144ce5d8aa1e5a157dd39af745a43bb

uglyog
2019-10-16 22:08
Maven will setup the classpath and system properties differently to Eclipse. How are you executing the tests? JUnit?

uglyog
2019-10-16 23:39
Oh, that's interesting. I'm going to remove that filterPacts

uglyog
2019-10-16 23:40
But I still want to know why this is affecting you and not anyone else

uglyog
2019-10-16 23:42
What JVM version are you using?

uglyog
2019-10-16 23:44
Ah, I've found the problem (I think).

uglyog
2019-10-16 23:45
You're using the SpringRestPactRunner, which filters out everything except http pacts. SpringMessagePactRunner is the one you need to use

uglyog
2019-10-16 23:46
That's why removing the filterPacts method fixes the issue

uglyog
2019-10-16 23:48
I'm going to make that error message more explicit

kashikar.harsh
2019-10-17 05:44
Thanks @uglyog, also if we can add an example of message pact for spring, it will help

kashikar.harsh
2019-10-17 05:44
I was not aware that SpringMessagePactRunner exists, my bad if i have missed any document

kashikar.harsh
2019-10-17 05:51
After changing to SpringMessagePactRunner, it proceed with further verifcation

kashikar.harsh
2019-10-17 05:51
Thanks you @uglyog and @simon.waterhouse

uglyog
2019-10-17 06:26
Sorry, it's not your fault, there is no documentation on that.

simon.waterhouse
2019-10-17 08:29
Good work @uglyog - thanks for the speedy response !!

nathan.deamer
2019-10-17 15:04
Any tips on how to use the pact gradle plugin for pactVerify? I am using gradle5 and trying to start a spring boot app with a profile - but it doesn't seem to be picking up the spring.profiles.active. ``` if ('pactVerify' in gradle.startParameter.taskNames) { startProviderTask = 'startApp' terminateProviderTask = 'stopApp' hasPactsFromPactBroker(System.getenv('PACT_BROKER_URL'), authentication: ['Bearer', System.getenv('PACT_BROKER_TOKEN')]) }``` ```task startAppProcess() { doLast() { ExecutorService es = Executors.newSingleThreadExecutor() es.submit({ project.javaexec { classpath = project.sourceSets.main.runtimeClasspath main = 'com.nathandeamer.Application' args 'spring.profiles.active=test' } } as Callable) } } task startApp(dependsOn: startAppProcess) { doLast { def timeTaken = 0 while (timeTaken < 120) { try { if (Request.Get('http://localhost:8080/actuator/health').execute().returnResponse().getStatusLine().getStatusCode() == 200) { return } } catch (ConnectException ignored) { } timeTaken++ sleep(500) } throw new GradleException('Failed to start app in 1 minute.') } }``` Or is there a better way to do this?

gopinathlangote11
2019-10-17 15:41
Feels like you are trying to make application up before pact verification. wondering why you want to do pact verification against you local env. Why not with stable env?


nathan.deamer
2019-10-17 15:57
1. Start up my provider. 2. Get the PACTs from the pact broker 3. Verify them against running provider.

okereke.ruth
2019-10-17 20:56
has joined #pact-jvm

abubics
2019-10-17 22:54
Some of us use this copypasta between years of codebases :stuck_out_tongue: ``` import com.wiredforcode.gradle.spawn.* task startProvider(type: SpawnProcessTask, dependsOn: 'assemble') { def path = "$buildDir/libs" if (new File(path).exists()) { def jarFiles = new FileNameByRegexFinder().getFileNames(path, /<your-app>.*\.jar/) command "java -jar ${jarFiles[0]}" ready 'Application started' } } startProvider.doLast { Thread.sleep(100) } task stopProvider(type: KillProcessTask) { } ```

abubics
2019-10-17 22:56
@gopinathlangote11 It's totally reasonable to want to run Pact tests on local :slightly_smiling_face: the style I encourage people to write them in is like unit tests for the network interface. I know that's not the only way people use Pact, though.

hstene
2019-10-18 05:34
Boris is right. Why would you *not* want to run it locally? One of the benfits of Pact is that I as a developer can make a code change, verify that my change did not break any dependencies (and if it did; fix them) before I even commit my code. Testing locally on my machine is *ABSOLUTELY* a desired feature, @gopinathlangote11

nathan.deamer
2019-10-18 07:41
Thanks guys. Will let you know how I get on

nathan.deamer
2019-10-18 09:38
Yep, that is working. Now just dealing with spring boot issues not overriding my beans with mocks

jennifer.molis
2019-10-18 16:04
has joined #pact-jvm

uglyog
2019-10-19 22:02
@dianaszaharia because of the way JUnit 5 works, we have not found a way to implement that

uglyog
2019-10-19 22:03
If you don?t provide a tag, it will use latest

roi.otero.morales
2019-10-21 12:53
has joined #pact-jvm

roi.otero.morales
2019-10-21 12:57
Hello Im having a problem when trying to use pact with the `pact-jvm-provider-spring:4.0.1` , I cannot make it able to verify the tests, they are being reported as `verification: result:OK` but they are not being pushed to the PactBroker therefore they are never verified there Im getting the error: `Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true')` Im using: ```@SpringBootTest(classes = {Application.class},properties={ "pact.provider.version=0", "pact.verifier.publishResults=true" }, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)``` as well tried with the quotes on true ` "pact.verifier.publishResults='true'"` I have it as well on the application properties: ```pact: verifier: publishResults: 'true' provider: version: 0```

uglyog
2019-10-21 20:52
Which test runner are you using?

roi.otero.morales
2019-10-21 20:56
Hey, i will check it tomorrow but i think the PactRunner, anyways i found a way, its a system property. So in gradle i defined as a system property. Looks like the library is not getting the environment properties, just system ones.

roi.otero.morales
2019-10-21 20:58
I was debugging the pact jvm library and there is a class, i cannot recall the name, in kotlin, that checks for the state of the variable pact.verifier.publishResults, but it checks with System.getProperty() not System.getEnv()

uglyog
2019-10-21 21:13
The base runner only uses JVM system properties. If you use the runner from the spring module, it will use values from the spring context

roi.otero.morales
2019-10-22 08:40
umm well i was using this module: `testCompile 'au.com.dius:pact-jvm-provider-spring:4.0.1'` And only works from the JVM system properties :disappointed:

roi.otero.morales
2019-10-22 08:41
I was using as well the runner `@RunWith(SpringRestPactRunner.class)`

sandhyarani.gabbi
2019-10-22 13:04
Hi Team, StringMatcher and numberType matchers are not allowing "/" or ":" in the name field in 4.0.x version. It was working fine till 3.6.x version. Is this working as intended?

uglyog
2019-10-22 22:18
Can you provide the error you are getting?

uglyog
2019-10-22 22:20
That runner should use the spring context for the properties.

uglyog
2019-10-22 22:21
But maybe not that one (it works for the broker properties). But if the JVM system property is working, just use that

roi.otero.morales
2019-10-23 10:35
exactly, it works for the broker properties, i was debugging the code that checks for the property `pact.verifier.publishResults` and uses `System.getProperty(),` instead of `System.getEnv()`

bartlomiej.twarog
2019-10-23 12:51
has joined #pact-jvm

sandhyarani.gabbi
2019-10-23 13:06
@uglyog ERROR a.c.d.p.c.BaseJdkMockServer:204 [Thread-2] Failed to generate response au.com.dius.pact.core.model.InvalidPathExpression: ":" is not allowed in an identifier in path expression "$.container_records[0].state[0].aDataItem[0].OrgNamBVLKey_CDF[0].OrgNamBVLNameKey_Col_CDF[0].OrgNamBVLNameKey_CDF[0].OrgNamBVLLocalNamedatadefinition:CDF" at index 149

uglyog
2019-10-23 21:21
Can you raise an issue for that on the GitHub project

vince.grossi
2019-10-26 19:42
has joined #pact-jvm

vince.grossi
2019-10-26 19:49
Hi, I?m trying to integrate pact contract creation with cucumber, but I?d like to create contract with loose response matching. Any pointer would be appreciated.

uglyog
2019-10-26 22:43
what do you mean by loose response matching?

vince.grossi
2019-10-26 23:39
I mean instead of doing strict body matching like

vince.grossi
2019-10-26 23:43
I'd rather generate something like:

uglyog
2019-10-26 23:50
Ok, you want to expose the DSL matching methods to cucumber steps?

vince.grossi
2019-10-27 00:02
I'm not exactly sure of what I'm looking for ... Just trying to know if anything has already been done on cucumber and pact so I can dig in a little bit more. I've seen https://github.com/remondis-it/pact-consumer-builder which offers POJO to PactDSLJSonBody mapping. it'd be interesting to have a JSON to PactDSLJsonBody mapper which I could use in my cucumber testing. I have some steps where I can mock my response, I'd like to use these steps to generate a contract, so I can make sure my provider is compliant with the mocking

wongso_a
2019-10-29 12:51
The situation we are in is that not all consumers of the API are tagged yet. What we were hoping as an interim solution is to run the provider tests with the latest pacts if the consumer's pact hasn't been tagged and run with the latest tag if it exists. We have worked around this by implementing two executions in the POM file. However, if there is a way to do it all in one execution, I would be keen to know.

rafael.anachoreta
2019-10-31 10:44
has joined #pact-jvm

rafael.anachoreta
2019-10-31 11:57
good afternoon! I?m trying to use `pact-jvm-consumer-junit`?s version 4.0.2 and having trouble understanding how to use the overriden `runTest(MockServer, PactTestExecutionContext)` to run multiple tests against the same provider

rafael.anachoreta
2019-10-31 11:59
I think the README is a bit outdated (https://github.com/DiUS/pact-jvm/tree/master/consumer/pact-jvm-consumer-junit) , but by extending `ConsumerPactTest` I get to @Override `runTest()` my question - what purpose does runTest() serve when I have multiple tests? Should it be calling the other test methods? Should I just ignore it and add the @test annotation to my custom tests?

andreas
2019-10-31 12:45
Hi All, I am trying to implement Pact in our Android Project, but it seems as if the httpClient differs/conflicits between Java and AndroidJava. This seems to be a problem in Pact JVM 4.0.2, and the Android Workshop is on Pact 3.3.6 Are anyone able to use the lastest Pact-jvm in an Android (Java8/Kotlin project)

kist
2019-10-31 12:46
has joined #pact-jvm

kist
2019-10-31 12:49
Our best guess at the reason for the error is the accepted answer of this stackoverflow


andreas
2019-10-31 12:56
Thorbjørn and I are from the same project. And The above is just a further detailing.

andreas
2019-10-31 12:57
We would rather avoid suggesting a special android version of Pact, but perhaps it is possible with some Java magic to use both (I am mostly on JavaScript)

anddreiu
2019-10-31 17:30
Hi all. I would appreciate if anybody has any idea for the above question related to how to avoid calling an url by the XmlBodyMatcher? I think it tries to open the url when it parses the XML. Many thanks.

abubics
2019-10-31 23:39
If you're building an Android consumer, there shouldn't be any http client coming from Pact, just your own app's outbound request client.

abubics
2019-10-31 23:40
But I haven't done Pact+Android for about a year, so my knowledge isn't super-current

abubics
2019-10-31 23:41
Oh, it's the content-type parsing . . . not the request client :thinking_face:

abubics
2019-10-31 23:43
You may be able to use that SO answer, and exclude httpclient from the Pact dependency, and include another? But it does sound like a compat bug, maybe @uglyog has some input/ideas :slightly_smiling_face:

vetisanvasile
2019-11-04 14:30
~Hi guys, I have a question related to <https://github.com/DiUS/pact-jvm/issues/550> Should I post a comment in that issue?~ LATER EDIT: I kinda figured out :slightly_smiling_face:

antonello
2019-11-05 15:10
@uglyog The one above is from one of the devs of the client I?m working with. Another contribution for this side of the world :slightly_smiling_face:

antonello
2019-11-06 09:28
@greg.pappas is the author!

greg.pappas
2019-11-06 09:28
has joined #pact-jvm

andreas
2019-11-06 10:00
ok - @abubics - thank you for the information. We will make an issue on the pact-jvm repo for this. To get more awareness of the issue. Thanks

greg.pappas489
2019-11-06 17:03
has joined #pact-jvm

uglyog
2019-11-09 02:30
PR has been merged! Thanks!

antonello
2019-11-10 10:17
@greg.pappas

thomas.scheuchzer2
2019-11-11 13:32
Are pending pacts already implemented in pact-jvm? http://blog.pact.io/p/d7c9601f-e2ca-4208-b1c0-f02eaf96c3c2/ Can't find any hint about this in the code and I guess there should be some additional code for this. Though it's also possible that I'm just blind :slightly_smiling_face:

uglyog
2019-11-11 21:12
@thomas.scheuchzer2 I haven?t done any work on that yet. There is an issue to track it.

ryan.dens
2019-11-11 21:20
@uglyog is there any other issue besides https://github.com/DiUS/pact-jvm/issues/942?

ryan.dens
2019-11-11 21:27
Looking forward to this feature! Is there any plan to decompose this work? I?d be happy to take on at least a chunk of it

uglyog
2019-11-11 21:35
No, that's the issue for it. It points to another issue that contains the details of the change.

uglyog
2019-11-11 21:38
@ryan.dens if you want to have a look at the other issue, we need to work out what needs to be done. As far as I understand, there is a new endpoint on the broker. So we need to look for that link, and if it is there, use it otherwise fall back to the existing functionality

jks
2019-11-12 14:18
has joined #pact-jvm

rafael.anachoreta
2019-11-13 14:15
hello! maybe a silly question, but was is the recommendation for running the `can-i-deploy` command on the jvm environment? Should I just use the ruby CLI or is there a JVM implementation of it (similar to what pact-node has)?

ingo.griebsch
2019-11-13 17:04
has joined #pact-jvm

abubics
2019-11-13 23:38
We tend to just run the CLI version, and its runtime should be transparent. Since it's running on CI, just run the script in an explodey way, such as `#!/bin/bash -eu` to make sure it breaks the build if it can't deploy rn

abubics
2019-11-13 23:39
but, as usual, the correct answer is "it depends", and I don't know how complex your infra and pipelines are :slightly_smiling_face:

akazantseva2
2019-11-14 11:15
has joined #pact-jvm

rafael.anachoreta
2019-11-14 16:54
thank you, I got some extra answers on the #pact-broker thread and I think I?ve managed to proceed :muscle:

rafael.anachoreta
2019-11-14 16:56
:wave: I?m looking into publishing my pacts to my broker I went into the docs, but the consumer?s README points to the provider library (which is confusing - https://github.com/DiUS/pact-jvm/tree/master/consumer/pact-jvm-consumer-groovy#publishing-your-pact-files-to-a-pact-broker) To further add to my confusion, the variable I?m supposed to set with my pact version is called `providerVersion` and was introduced in favor of `version`. Why was that? :thinking_face: My understanding is that you should only ever be publishing the pacts from the consumer?s side (hence my confusion on this gradle task being on pact/provider/gradle), so the version would just be the version of the consumer?s pact that was published. The verification is when I?d add a version for the provider, but not on the publishing of the actual pact. Am I wrong? https://github.com/DiUS/pact-jvm/blob/master/provider/pact-jvm-provider-gradle/src/main/groovy/au/com/dius/pact/provider/gradle/PactPublish.groovy#L17

uglyog
2019-11-14 20:48
The provider version is used to store the verification results. So a consumer with a particular version publishes a pact, then a provider with it's version publishes that it's been successfully verified. That way you know which versions of a consumer are compatible with the versions of the provider.

rafael.anachoreta
2019-11-15 08:08
yes, exactly! but currently the task to publish the Pact (not the verification) also lives within the provider?s library

uglyog
2019-11-15 08:20
:man-shrugging: doesn't matter which library it's in, there is no consumer gradle plugin

rafael.anachoreta
2019-11-15 08:21
I suppose :stuck_out_tongue: but anyway, the passed in variable is also called ?providerVersion? despite being the consumer version but ye it doesn?t really matter, I just wanted to confirm my thinking was right and for that I thank you :bow:

sabil.beladri
2019-11-18 16:47
Hi, I'm looking for some examples of groovy tests using RestPactRunner, MockMvcTarget, @State and stubs, are there any around here? Here's the full story why I'm asking this: I'm a bit struggling to have a spring provider validation running fine in Groovy. I have it already working fine in Kotlin, using MockMvcTarget, coupled with @State and stubs When..thenReturn But upon trying to port this to Groovy, I'm facing weird issues [1]. Do we have examples of how to run such a validation in Groovy? I checked pact-jvm doc [2] but could not find an example using @State and stubs When..thenReturn 1: kotlin.TypeCastException: null cannot be cast to non-null type au.com.dius.pact.provider.junit.target.Target 2: https://github.com/DiUS/pact-jvm/tree/master/provider/pact-jvm-provider-spring/src/test/groovy/au/com/dius/pact/provider/spring

kashikar.harsh
2019-11-18 17:47
Hey All

kashikar.harsh
2019-11-18 17:47
I am working on writing contract tests using pact-jvm for amqp protocol

kashikar.harsh
2019-11-18 17:48
and was looking for an example where multiple contracts tests written for same provider and consumer

kashikar.harsh
2019-11-18 17:49
Basically need to understand how this line of code will work if there are multiple tests in the same java file

kashikar.harsh
2019-11-18 17:50
Since there is no context to it, it always returns the same payload and hence in case of multiple tests, only one test pass

uglyog
2019-11-18 20:49
Groovy should be pretty similar to ones in Java and Kotlin. Have a look in the pact-jvm test folders, there are lots of Groovy tests.

uglyog
2019-11-18 20:51
Not sure what you mean by stubs When..thenReturn?

291636938
2019-11-19 06:30
has joined #pact-jvm

291636938
2019-11-19 06:30
Hi @channel, I using version 3 of pact and is able to generate the pact json file and do the consumer test, but when I turn to run the provider test, it came out error with message "Exception: No tests found matching Method", I use the springboot 2.x , pact 3.6.0, and my demo project is located at https://github.com/wuhuanxing/pact_demo , Ive struggled it for few days, really hope some one can help me , Thank very much!

felipe
2019-11-19 07:44
has joined #pact-jvm

felipe
2019-11-19 07:46
Hi all! im trying to verify pacts with the gradle plugin but im getting always a 400 bad request from nginx. From postman with https://myurl.com:443/service/path works perfectly. im out of ideas this is my gradle ```plugins { id "java" id "au.com.dius.pact" version "4.0.3" } task('getToken') { doLast { } } pact { serviceProviders { wmsBackend { protocol = 'https' host = 'http://myserviceurl.com' port = 443 path = '/' //insecure = true requestFilter = { req -> req.addHeader('Authorization', 'Bearer sometoken') } hasPactsWith('WmsFrontend') { pactFileLocation = file("$rootDir/../pacts/frontend") } hasPactsWith('Plentymarkets') { pactFileLocation = file("$rootDir/../pacts/plentymarkets") } } } reports { defaultReports() // adds the standard console output markdown // report in markdown format json // report in json format } } ```

felipe
2019-11-19 07:46
My pact makes a boring get: ```"request": { "headers": { "Authorization": "Bearer token", "Content-Type": "application/json" }, "method": "GET", "path": "/api/v1/entity/entty2/1", "body": {}```

felipe
2019-11-19 07:48
Check my latest message in the channel. There is an example of working build.gradle.

sabil.beladri
2019-11-19 08:14
thanks, I'll look a bit further on pact-jvm tests by stubs I meant something like ```when(awesomeBusinessLogic.getById(any(UUID.class))) .thenReturn(myTestHelper.generateRandomReturnData(UUID.randomUUID(), ExampleEnum.ONE))```

audun.halland
2019-11-19 09:53
has joined #pact-jvm

m.kwiecien
2019-11-19 10:17
has joined #pact-jvm

291636938
2019-11-19 13:12
seem not work on my project...can u take a time look at my demo project? thanks

uglyog
2019-11-19 20:38
Oh, you mean Mockito stubs

uglyog
2019-11-19 20:40
You use the different descriptions in the pact file to be mapped to different test methods using the annotation on the test method.

uglyog
2019-11-19 20:47
You?ll need to have a look at the nginx logs to see why the request is being rejected. Also, if you enable debug logs you will see the exact request being made, including headers. You can then try that in postman.

ft1704602
2019-11-20 04:19
has joined #pact-jvm

felipe
2019-11-20 04:26
I was using the request filter to set headers and it fails if the pacts have headers. Still investigating that issue

felipe
2019-11-20 04:27
I don?t have much time. I think is better that you look at my code

291636938
2019-11-20 05:46
hi, when I start the provider test with pact, it came out `failed: Connection refused `Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)`, I used springBoot v2, and pact v3, project at https://github.com/wuhuanxing/pact_demo , do I need to start my provider program before the provider test? is it possible to load the specified controller and minimum spring context to do the contract test?

291636938
2019-11-20 06:40
# run command ./gradlew pactVerify > Task :pactVerify_myProvider FAILED Verifying a pact between myConsumer and myProvider [Using File /Users/huanxing.wu/demo_pact/target/pacts/myConsumer-myProvider.json] Given sayHello WARNING: State Change ignored as there is no stateChange URL a request to /hello Request Failed - Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused) Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true') Failures: 0) Verifying a pact between myConsumer and myProvider - a request to /hello Given sayHello Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)

291636938
2019-11-20 07:03
I found this problem can be resolved by start my real provider service(spring app), but my question is how can I use a mocked provider for provider contract test? i think is not good if we do the testing on real production service. I newbie on this , could someone help explain it to me in plain word , thank you very much!

uglyog
2019-11-20 07:12
The point of the provider test is to verify the real provider adheres to the contract. Verifying a mock provides no benefit.

291636938
2019-11-20 07:19
Well , what if the provider test will modify the data on DB? then in this way the contract test is not repeatable, and if the test running on PROD ENV, that would be terrible. on the other way ,if we can mock the endpoints( and it's dependencies ) we need to test, like the mockMvc way , that would be nice .

uglyog
2019-11-20 07:23
You can use MockMVC with Pact. That does not mock your provider, but tests the actual controllers. It's mocks out the Spring MVC environment. See https://github.com/DiUS/pact-jvm/tree/master/provider/pact-jvm-provider-spring

291636938
2019-11-20 07:27
yes that's what I meaning and looking for , thank you very much

291636938
2019-11-20 07:47
hello @uglyog, I've followed the link above and got below error, still the same error : cannot connect server:

291636938
2019-11-20 07:50
thank you for your kindness and patient

291636938
2019-11-20 07:52
and my pact config on build.gradle is :


291636938
2019-11-20 09:01
hello @uglyog good news! after a painful struggling, I'm now able to run test with mockMvc successfully , really thank you for your help. now I have one more question ,how to run only one test case :

uglyog
2019-11-20 09:06
That is not the test method, it is the state change method. Just run the test from the class name

291636938
2019-11-20 09:15
:joy: ok thank you

kashikar.harsh
2019-11-21 09:37
Is there a documentation for this that I can refer to? Tried looking for annotations, couldn't find it

kashikar.harsh
2019-11-21 12:13
I could achieve this with the use of different fragments

roi.otero.morales
2019-11-21 13:54
Hello everyone! , I have 2 questions is there a way to `pactPublish` using Junit instead of Gradle plugin? is there a way to not fail `pactPublish` when there is no folder containing pacts? (I want to run pactPublish even if the Repo doesnt have consumers and only providers to have a standarized pipeline) `Execution failed for task ':pactPublish'.` > `http://java.io``.FileNotFoundException: /<somepath>/build/pacts`

vijay.chinthala
2019-11-21 19:21
has joined #pact-jvm

vijay.chinthala
2019-11-21 19:24
@felipe can you please help me with example code how did you add the Authorization to the header, I am trying to find a solution while executing the pactVerify the token should be generated dynamically and set the header Authorization

crummynz
2019-11-21 23:39
has joined #pact-jvm

crummynz
2019-11-21 23:51
The docs on https://github.com/DiUS/pact-jvm/tree/master/consumer/pact-jvm-consumer-junit say to "extend ConsumerPactTestMk2". But in the source I don't see a file with that name, though there is "ConsumerPactTest.java". What should I use?

uglyog
2019-11-21 23:57
Ah, those docs are out of date. Just drop the Mk2 off

crummynz
2019-11-22 00:24
Do the JVM pact libraries support rabbitmq mocking?

uglyog
2019-11-22 00:25
The message support is abstracted and not specific to any messaging implementation

crummynz
2019-11-22 01:02
I have a service that listens to a rabbit queue, processes messages, and sends responses on another queue. Does that mean I need a consumer and provider to test this?

kiranpatel11
2019-11-22 01:06
if you deal with content before sending it to next queue, you should consider tests for that, or just have tests for the consumer in chain which deals with the content of the message.

kiranpatel11
2019-11-22 01:07
if you are just routing based on header or something, you aren't really dealing with contract, you don't need to have a test for that

crummynz
2019-11-22 01:42
Seems like I'm best off just instantiating the class that sends the responses with mock dependencies and not booting up the whole app. Is this usually the way to do it?

kiranpatel11
2019-11-22 02:05
You should mock the layers after your request is parsed and validated. Refer : https://docs.pact.io/best_practices/provider#only-stub-layers-beneath-where-contents-of-the-request-body-are-extracted

crummynz
2019-11-22 02:32
Is this an example of how I would call my rabbitmq handler? ``` @get:Rule val provider = MessagePactProviderRule("provider1", this) @Test fun test() { MyHandler().handle(Delivery(null, null, provider.message)) }```

crummynz
2019-11-22 02:34
I have a @Pact annotated MessagePact method elsewhere, and in the blog post https://dius.com.au/2017/09/22/contract-testing-serverless-and-asynchronous-applications/ it seems that I'm supposed to attach some messageHandler to it, but I don't know where I get messageHandler from. Is that MyHandler() in my earlier code?

uglyog
2019-11-22 02:40
The idea is that you split your code into two parts: the bit that generates the message, and the bit that puts it into the message queue. The contract is then with the code that creates the message. You can then test that with a Pact test without having to have a message queue.

crummynz
2019-11-22 02:41
huh OK. So just check that my object deserializes?

uglyog
2019-11-22 02:41
Well, if you have some code that deserializes and then processes the message, you could let that be your handler

crummynz
2019-11-22 02:51
The example refers to PactMessageBuilder which I don't seem to have. Is MessagePactBuilder a replacement?

uglyog
2019-11-22 02:58
It's MessagePactBuilder

uglyog
2019-11-22 02:58
The example is wrong.

kiranpatel11
2019-11-22 03:20
@crummynz this may help you visualize how pact for messaging is desinged :

crummynz
2019-11-22 03:23
Thanks, that makes sense. I think I'm stuck on step 2.

uglyog
2019-11-22 03:23
awesome diagram! Can we put that in the Pact docs?

crummynz
2019-11-22 03:24
Is the code in this guide still accurate? https://reflectoring.io/cdc-pact-messages/ The `setMessage(byte[] message)` method seems a bit... magic?

kiranpatel11
2019-11-22 03:25
sure...It helped me a lot to educate others....!!

uglyog
2019-11-22 03:29
You don't need the `setMessage` function, you can call `messageProvider.getMessage()`

uglyog
2019-11-22 03:30
Tom didn't write that blog post that long ago, so it should still be good

crummynz
2019-11-22 04:48
I found your pact-maven-amqp-test repo @uglyog. I upgraded the library version here: https://github.com/uglyog/pact-maven-amqp-test/compare/master...crummy:master However, that gets me this error: ```java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.rangeCheck(ArrayList.java:657) at java.util.ArrayList.get(ArrayList.java:433) at http://au.com.dius.pact.consumer.junit.MessagePactProviderRule.parsePacts(MessagePactProviderRule.java:194) at http://au.com.dius.pact.consumer.junit.MessagePactProviderRule.access$500(MessagePactProviderRule.java:28)```

crummynz
2019-11-22 04:49
I was able to resolve it by changing line 26 to include a providerState (change to `return builder.given("bar")`) and line 33 to the same (change to `@PactVerification({"foo", "bar"})`). Is a state required now?

uglyog
2019-11-22 05:06
on the provider side you would get a warning if there was no state change handler for that state, but otherwise, no

crummynz
2019-11-22 05:13
So the test should still pass with my changes? Should I file a bug?

uglyog
2019-11-22 05:15
yeah, sure.

pavel.azarau
2019-11-22 17:04
has joined #pact-jvm

thomas.scheuchzer2
2019-11-25 10:23
When I build pact-jvm on my local machine I get a test failure on master: `http://au.com``.dius.pact.provider.junit.PactRunnerSpec > PactRunner throws an exception if the pact source throws an IO exception FAILED` Is this the current status on master or is it my build setup?

uglyog
2019-11-25 22:26
master builds ok on my machine, as well as on Travis CI and Apveyor

hande.sagar
2019-11-26 03:21
I am not able to see branch name in tag for published event. I am expecting branch name here along with commit number.

hande.sagar
2019-11-26 03:22
cant see branch name here , I can only see commit number.

uglyog
2019-11-26 03:23
You'll need to show us your config

hande.sagar
2019-11-26 03:24
I am using such mvn command to publish it

hande.sagar
2019-11-26 03:24
mvn clean test -Dpactbroker.host=http://kube-pact -Dpact.verifier.publishResults=true -Dpact.provider.version=0a44cd1051a1459dd4148ca6ff1c3f0ef5fdc157 -Dpact.provider.tag=feature/FMPSU-236-PACT-Publish-issue -Dpact.tag=feature/FMPSU-236-PACT-Publish-issue

hande.sagar
2019-11-26 03:25
I am using such mvn command to publish it mvn clean test -Dpactbroker.host=http://kube-pact -Dpact.verifier.publishResults=true -Dpact.provider.version=0a44cd1051a1459dd4148ca6ff1c3f0ef5fdc157 -Dpact.provider.tag=feature/FMPSU-236-PACT-Publish-issue -Dpact.tag=feature/FMPSU-236-PACT-Publish-issue

hande.sagar
2019-11-26 03:26
this is my pom file

hande.sagar
2019-11-26 03:26
<plugin> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-maven_2.12</artifactId> <version>3.6.2</version> <configuration> <pactDirectory>${project.build.directory}/pacts</pactDirectory> <pactBrokerUrl>http://kube-pact</pactBrokerUrl> <!-- <pactBrokerUrl>http://pact-broker.pact-broker</pactBrokerUrl> --> <projectVersion>${pact.consumer.version}</projectVersion> <projectVersion>${pact.provider.version}</projectVersion> <trimSnapshot>true</trimSnapshot> <useManifestOnlyJar>false</useManifestOnlyJar> <tags> <tag>${pact.tag}</tag> </tags> <serviceProviders> <serviceProvider> <name>package-supplier-events</name> <verificationType>ANNOTATED_METHOD</verificationType> <!-- <stateChangeUrl>http://localhost:8080/tasks/pactStateChange</stateChangeUrl> --> <pactBrokerUrl>http://kube-pact/</pactBrokerUrl> <!-- <pactBrokerUrl>http://pact-broker.pact-broker</pactBrokerUrl>--> </serviceProvider> <serviceProvider> <name>package-supplier</name> <verificationType>ANNOTATED_METHOD</verificationType> <!-- <stateChangeUrl>http://localhost:8080/tasks/pactStateChange</stateChangeUrl> --> <pactBrokerUrl>http://kube-pact/</pactBrokerUrl> <!-- <pactBrokerUrl>http://pact-broker.pact-broker</pactBrokerUrl> --> </serviceProvider> </serviceProviders> <configuration> <pact.verifier.publishResults>false</pact.verifier.publishResults> </configuration> </configuration> </plugin>

uglyog
2019-11-26 03:29
You've circled the provider version in the screenshot. That will be the value of `-Dpact.provider.version`

uglyog
2019-11-26 03:30
The tags are displayed in blue

hande.sagar
2019-11-26 03:34
I want to see provider branch name

hande.sagar
2019-11-26 03:34
consumer branch name is showing properly

hande.sagar
2019-11-26 03:35
I am using these dependency

hande.sagar
2019-11-26 03:35
<dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> <scope>test</scope> </dependency> <dependency> <configurationParameters> junit.jupiter.conditions.deactivate = * junit.jupiter.extensions.autodetection.enabled = true junit.jupiter.testinstance.lifecycle.default = per_class </configurationParameters>

uglyog
2019-11-26 03:38
What version of Pact Broker are you using?

bethskurrie
2019-11-26 03:38
Perhaps you have an old version. The latest version definitely shows the tags.

bethskurrie
2019-11-26 03:40
Also, you need the latest pact-jvm version for the provider tagging support.

bethskurrie
2019-11-26 03:40
It was only added recently.

hande.sagar
2019-11-26 03:59
which version I should use

hande.sagar
2019-11-26 03:59
using these versions

hande.sagar
2019-11-26 03:59
<plugin> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-maven_2.12</artifactId> <version>3.6.2</version> <configuration> <pactDirectory>${project.build.directory}/pacts</pactDirectory> <pactBrokerUrl>http://kube-pact</pactBrokerUrl> <!-- <pactBrokerUrl>http://pact-broker.pact-broker</pactBrokerUrl> --> <projectVersion>${pact.consumer.version}</projectVersion> <projectVersion>${pact.provider.version}</projectVersion> <trimSnapshot>true</trimSnapshot> <useManifestOnlyJar>false</useManifestOnlyJar> <tags> <tag>${pact.tag}</tag> </tags> <serviceProviders> <serviceProvider> <name>package-supplier-events</name> <verificationType>ANNOTATED_METHOD</verificationType> <!-- <stateChangeUrl>http://localhost:8080/tasks/pactStateChange</stateChangeUrl> --> <pactBrokerUrl>http://kube-pact/</pactBrokerUrl> <!-- <pactBrokerUrl>http://pact-broker.pact-broker</pactBrokerUrl>--> </serviceProvider> <serviceProvider> <name>package-supplier</name> <verificationType>ANNOTATED_METHOD</verificationType> <!-- <stateChangeUrl>http://localhost:8080/tasks/pactStateChange</stateChangeUrl> --> <pactBrokerUrl>http://kube-pact/</pactBrokerUrl> <!-- <pactBrokerUrl>http://pact-broker.pact-broker</pactBrokerUrl> --> </serviceProvider> </serviceProviders> <configuration> <pact.verifier.publishResults>false</pact.verifier.publishResults> </configuration> </configuration> </plugin> </plugins>

bethskurrie
2019-11-26 04:21
The latest!

uglyog
2019-11-26 04:21
Latest is 4.0.3

uglyog
2019-11-26 04:23
```<artifactId>pact-jvm-provider-maven</artifactId> <version>4.0.3</version>```

hande.sagar
2019-11-26 04:51
ok, let me check

vijay.chinthala
2019-11-26 23:15
I am facing this issue Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true')

vijay.chinthala
2019-11-26 23:15
I am using the pact-jvm provider version 4.0.3

vijay.chinthala
2019-11-26 23:15
can you please help what configuration I need to set here in my gradle script

vijay.chinthala
2019-11-26 23:39
Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true')

vijay.chinthala
2019-11-26 23:40
I am getting problem, I have tried setting System.setProperty("pact.verifier.publishResults", 'true') and also did $export pact_verifier_publishResults='true' but no luck

vijay.chinthala
2019-11-26 23:40
I am using gradle script to configure the pact verify

vijay.chinthala
2019-11-26 23:41
please throw some light here what I am doing wrong here?

uglyog
2019-11-26 23:41
You need to set the properties on the test task


vijay.chinthala
2019-11-26 23:43
I am using gradle

vijay.chinthala
2019-11-26 23:43
``` task startProducer(type: com.github.psxpaul.task.JavaExecFork) { System.setProperty("JWT_PUBLIC_KEY", public_key) System.setProperty("pact.verifier.publishResults", 'true') classpath = sourceSets.main.runtimeClasspath main = 'com.five9.learningservice.LearningServiceApplication' stopAfter = pactVerify timeout = 45 waitForPort = 8080 waitForOutput = 'Started LearningServiceApplication' environment 'JWT_PUBLIC_KEY', public_key environment 'pact.verifier.publishResults', 'true' } pact { serviceProviders { learningService { startProviderTask = 'startProducer' if ('pactVerify' in gradle.startParameter.taskNames) { // hasPactsFromPactBroker(System.getenv('PACT_BROKER_URL'), authentication: ['Bearer', System.getenv('PACT_BROKER_TOKEN')]) hasPactWith('learningService') { // pactFile = file('build/pacts/learningServiceClient-learningServiceProvider.json') //used the latest pact contract to verify pactFile = url('broker-URL/pacts/provider/learningServiceProvider/consumer/learningServiceConsumerClient/version/1.0.0') System.setProperty("pact.verifier.publishResults", 'true') requestFilter = { req -> // Add an authorization header to each request req.addHeader('Authorization', 'Bearer ' + token ) } } } } } reports { defaultReports() // adds the standard console output json // report in json format } }```

uglyog
2019-11-26 23:45
Please read the answer to that SO question I posted above. System.setProperty, environment and -D will not work

vijay.chinthala
2019-11-26 23:47
test { systemProperty "pact.verifier.publishResults", "true" }

vijay.chinthala
2019-11-26 23:47
I tried this

vijay.chinthala
2019-11-26 23:47
but is is not working

vijay.chinthala
2019-11-26 23:49
```> Task :pactVerify_learningService returns a response which has status code 200 (OK) has a matching body (OK) publish message to Pubsub Topic returns a response which has status code 200 (OK) has a matching body (OK) Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true') BUILD SUCCESSFUL in 34s 9 actionable tasks: 8 executed, 1 up-to-date```

uglyog
2019-11-26 23:52
Oh, if you're using the PactVerify gradle task, then you need to use the -D option to gradle

vijay.chinthala
2019-11-26 23:54
$./gradlew -Dpact.verifier.publishResults=true pactVerify

vijay.chinthala
2019-11-26 23:54
I did this but that did not work for me

vijay.chinthala
2019-11-26 23:59
``` dependencies { classpath 'au.com.dius:pact-jvm-provider-gradle:4.0.3' classpath "gradle.plugin.com.github.psxpaul:gradle-execfork-plugin:0.1.10" }```

vijay.chinthala
2019-11-26 23:59
these deps I am using

vijay.chinthala
2019-11-27 00:21
is there a way I could use pact broker API and update it

vijay.chinthala
2019-11-27 00:22
I tried to update tag and version using the pact broker API but did not work

johnny.nilsson83
2019-11-27 08:01
has joined #pact-jvm

rafael.anachoreta
2019-11-27 16:17
A bit of an old thread, but it would be really cool to be able to set the defaults of `pactbroker.host` and `pactbroker.port` on the system Props without having to get them as properties. Much like what we have for the `@VerificationReports()` annotation and `'pact.verification.reports'` !

me1352
2019-11-27 17:01
has joined #pact-jvm

justaburneremailforso
2019-11-27 17:04
has joined #pact-jvm

vijay.chinthala
2019-11-27 18:49
@uglyog any thoughts why verify publish result not working for me?

vijay.chinthala
2019-11-27 18:52
and also I am could add the version and tags for consumer but not to provider

uglyog
2019-11-27 22:37
I don't know what you're doing wrong. I just tested my test project, and it works. Running `./gradlew pactVerify -d` I see the following in the logs: ```09:34:50.797 [WARN] [http://au.com.dius.pact.provider.ProviderVerifier] Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true')``` And then running `./gradlew pactVerify -d -Ppact.verifier.publishResults=true` ```09:38:58.592 [INFO] [http://au.com.dius.pact.provider.DefaultVerificationReporter] Published verification result of 'Failed(results=[{message=Request to provider failed with an exception, exception=org.apache.http.conn.HttpHostConnectException: Connect to localhost:5050 [localhost/127.0.0.1] failed: Connection refused (Connection refused), interactionId=1b17fc7ae206564ffa469025ed5b609e5b637c7c}], description=Request to provider method failed with an exception)' for consumer 'Consumer(name=Foo Web Client 2)'```

uglyog
2019-11-27 22:40
Also, I can create a gradle.properties file in the root project with `pact.verifier.publishResults=true` also works

vijay.chinthala
2019-11-27 22:51
@uglyog I was using -D instead of -P, now I don;t see the error that I used to see but then I also don;t see last verified status in the pact broker

vijay.chinthala
2019-11-27 22:51
``` publish message to Pubsub Topic returns a response which has status code 200 (OK) has a matching body (OK) BUILD SUCCESSFUL in 31s 8 actionable tasks: 3 executed, 5 up-to-date```

uglyog
2019-11-27 22:52
run it with `-d` abd check the debug logs

vijay.chinthala
2019-11-27 22:53
```14:43:16.676 [INFO] [http://au.com.dius.pact.provider.DefaultVerificationReporter] Skipping publishing verification results for source UrlSource(url=http://pact-broker:8080/pacts/provider/learningServiceProvider/consumer/LearningServiceConsumer/latest/dev, pact=null)```

vijay.chinthala
2019-11-27 22:54
Screen Shot 2019-11-27 at 2.53.31 PM


vijay.chinthala
2019-11-27 22:56
```14:43:16.332 [DEBUG] [http://au.com.dius.pact.provider.ProviderVerifier] Verifying via request/response 14:43:16.333 [DEBUG] [http://au.com.dius.pact.provider.ProviderClient] Making request for provider http://au.com.dius.pact.provider.gradle.GradleProviderInfo@109342d5[providerVersion=<null>,providerTag=<null>,name=learningService,protocol=http,host=localhost,port=8080,path=/,startProviderTask=startProducer,terminateProviderTask=<null>,requestFilter=pact_5ro4pgonc778ffgsjjbyhctr$_run_closure3$_closure4$_closure6$_closure7@514bb795,stateChangeRequestFilter=<null>,createClient=<null>,insecure=false,trustStore=<null>,trustStorePassword=changeit,stateChangeUrl=<null>,stateChangeUsesBody=true,stateChangeTeardown=false,isDependencyForPactVerify=true,verificationType=REQUEST_RESPONSE,packagesToScan=[],consumers=[ConsumerInfo(name='learningService', stateChange=null, stateChangeUsesBody=true, packagesToScan=[], verificationType=REQUEST_RESPONSE, pactSource=UrlSource(url=http://pact-broker/pacts/provider/learningServiceProvider/consumer/LearningServiceConsumer/latest/dev, pact=null), pactFileAuthentication=[])]]: 14:43:16.333 [DEBUG] [http://au.com.dius.pact.provider.ProviderClient] method: POST```

uglyog
2019-11-27 23:01
pactSource=UrlSource means it doesn't know it's coming from a pact broker, it could be any URL. Don't use `pactFile = url('broker-URL/pacts/provider/learningServiceProvider/consumer/learningServiceConsumerClient/version/1.0.0')`, instead look at the link I posted above on how to set it up to fetch the pacts from the broker

vijay.chinthala
2019-11-27 23:06
``` pact { serviceProviders { learningService { startProviderTask = 'startProducer' if ('pactVerify' in gradle.startParameter.taskNames) { // hasPactsFromPactBroker(System.getenv('PACT_BROKER_URL'), authentication: ['Bearer', System.getenv('PACT_BROKER_TOKEN')]) requestFilter = { req -> // Add an authorization header to each request req.addHeader('Authorization', 'Bearer ' + token ) } hasPactWith('learningService') { // pactFile = file('build/pacts/learningServiceClient-learningServiceProvider.json') //used the latest pact contract to verify pactFile = url(PACT_BROKER_URL + 'pacts/provider/learningServiceProvider/consumer/LearningServiceConsumer/versions/1.0.5') } } } } reports { defaultReports() // adds the standard console output json // report in json format } }```

vijay.chinthala
2019-11-27 23:06
this is my pact config in the gradle, it looks fine

uglyog
2019-11-27 23:09
No, it's wrong. Use `hasPactsFromPactBroker`

vijay.chinthala
2019-11-27 23:11
``` pact { serviceProviders { learningService { startProviderTask = 'startProducer' if ('pactVerify' in gradle.startParameter.taskNames) { requestFilter = { req -> // Add an authorization header to each request req.addHeader('Authorization', 'Bearer ' + token ) } // You can get the latest pacts from the broker hasPactsFromPactBroker(PACT_BROKER_URL) // And/or you can get the latest pact with a specific tag hasPactsFromPactBrokerWithTag(PACT_BROKER_URL,"feat1") } } } reports { defaultReports() // adds the standard console output json // report in json format } }```

vijay.chinthala
2019-11-27 23:11
like this?

vijay.chinthala
2019-11-27 23:11
```> Task :pactVerify_learningService WARNING: There are no consumers to verify for provider 'learningService'```

uglyog
2019-11-27 23:12
The name needs to match what is in your broker, which is leaningServiceProvider

vijay.chinthala
2019-11-27 23:15
``` pact { serviceProviders { leaningServiceProvider { startProviderTask = 'startProducer' if ('pactVerify' in gradle.startParameter.taskNames) { requestFilter = { req -> // Add an authorization header to each request req.addHeader('Authorization', 'Bearer ' + token ) } // You can get the latest pacts from the broker hasPactsFromPactBroker(PACT_BROKER_URL) // And/or you can get the latest pact with a specific tag hasPactsFromPactBrokerWithTag(PACT_BROKER_URL,"feat1") } } } reports { defaultReports() // adds the standard console output json // report in json format } }```

vijay.chinthala
2019-11-27 23:15
```> Task :pactVerify_leaningServiceProvider WARNING: There are no consumers to verify for provider 'leaningServiceProvider'```

uglyog
2019-11-27 23:17
:man-shrugging: Can you check the name in your broker?

uglyog
2019-11-27 23:18
Hmm, looks correct from the previous URL

uglyog
2019-11-27 23:20
You only need to use one of the two lines: ``` // You can get the latest pacts from the broker hasPactsFromPactBroker(PACT_BROKER_URL) // And/or you can get the latest pact with a specific tag hasPactsFromPactBrokerWithTag(PACT_BROKER_URL,"feat1")```

uglyog
2019-11-27 23:21
Not both

vijay.chinthala
2019-11-27 23:23
awsome :slightly_smiling_face:

vijay.chinthala
2019-11-27 23:23
it worked

vijay.chinthala
2019-11-27 23:24
Screen Shot 2019-11-27 at 3.24.07 PM

vijay.chinthala
2019-11-27 23:24
I have asked to verify only for feat1

vijay.chinthala
2019-11-27 23:24
hasPactsFromPactBrokerWithTag(PACT_BROKER_URL,"feat1")

vijay.chinthala
2019-11-27 23:25
but I see it has updated all the consumer versions

uglyog
2019-11-27 23:25
It will update all versions where the pact file is the same

vijay.chinthala
2019-11-27 23:35
ok got it

vijay.chinthala
2019-11-27 23:36
Thank you very much for your help on this :slightly_smiling_face:

vijay.chinthala
2019-11-27 23:38
one more thing, from the gradle.properties version is being picked up and updating in the pact broker

vijay.chinthala
2019-11-27 23:38
what is configuration I need to use for tag

vijay.chinthala
2019-11-27 23:39
for provider tag

uglyog
2019-11-27 23:41
You can use what ever property you want, it needs to be the second parameter to hasPactsFromPactBrokerWithTag

vijay.chinthala
2019-11-27 23:42
no I mean how to set the tag for provider?

vijay.chinthala
2019-11-27 23:42
or we sent the tag to provider?

vijay.chinthala
2019-11-27 23:44
every time I run the pactVerify I see the pact broker duplicating versions

vijay.chinthala
2019-11-27 23:44
Screen Shot 2019-11-27 at 3.43.26 PM


vijay.chinthala
2019-11-27 23:56
``` pact { serviceProviders { learningServiceProvider { startProviderTask = 'startProducer' if ('pactVerify' in gradle.startParameter.taskNames) { requestFilter = { req -> // Add an authorization header to each request req.addHeader('Authorization', 'Bearer ' + token ) } providerVersion = { 'featBranch '+ '-' + 'abbrid1' } providerTag = { 'featBranch' } hasPactsFromPactBroker(PACT_BROKER_URL) // And/or you can get the latest pact with a specific tag // hasPactsFromPactBrokerWithTag(PACT_BROKER_URL,"feat1") // hasPactWith('learningService') { // pactFile = file('build/pacts/learningServiceClient-learningServiceProvider.json') // //used the latest pact contract to verify // pactFile = url(PACT_BROKER_URL + 'pacts/provider/learningServiceProvider/consumer/LearningServiceConsumer/versions/1.0.5') // } } } } reports { defaultReports() // adds the standard console output json // report in json format } }```

vijay.chinthala
2019-11-27 23:57
I have tired what you have advised but still I see duplicate entries

vijay.chinthala
2019-11-27 23:58
Screen Shot 2019-11-27 at 3.57.51 PM

uglyog
2019-11-28 00:00
@bethskurrie would be the best person to tell you why there are duplicate rows. But at least you're getting results

bethskurrie
2019-11-28 00:03
Most likely because the same pact has been verified multiple times. This view shows every verification.

bethskurrie
2019-11-28 00:04
As you can see, the timestamp and the verification number from the verifications are different

bethskurrie
2019-11-28 00:05
Choose the "latest for consumer version and provider version" and you'll only see one.

bethskurrie
2019-11-28 00:28
In the latest version of the broker, I've made that the default view.

vijay.chinthala
2019-11-28 00:39
Thanks Beth

vijay.chinthala
2019-11-28 00:40
``` pact { serviceProviders { learningServiceProvider { startProviderTask = 'startProducer' if ('pactVerify' in gradle.startParameter.taskNames) { requestFilter = { req -> // Add an authorization header to each request req.addHeader('Authorization', 'Bearer ' + token ) } providerVersion = { 'featBranch '+ '-' + 'abbrid1' } providerTag = { 'featBranch' } hasPactsFromPactBroker(PACT_BROKER_URL) // And/or you can get the latest pact with a specific tag // hasPactsFromPactBrokerWithTag(PACT_BROKER_URL,"feat1") // hasPactWith('learningService') { // pactFile = file('build/pacts/learningServiceClient-learningServiceProvider.json') // //used the latest pact contract to verify // pactFile = url(PACT_BROKER_URL + 'pacts/provider/learningServiceProvider/consumer/LearningServiceConsumer/versions/1.0.5') // } } } } reports { defaultReports() // adds the standard console output json // report in json format } }```

vijay.chinthala
2019-11-28 00:40
here is my pact configuration, can you please help how to filter or select the specific consumer and provider version

vijay.chinthala
2019-11-28 00:44
```> Task :pactVerify_learningServiceProvider Verifying a pact between LearningServiceConsumer and learningServiceProvider [from Pact Broker http://pact-broker/pacts/provider/learningServiceProvider/consumer/LearningServiceConsumer/version/1.0.5]```

vijay.chinthala
2019-11-28 00:45
every time I run the pactVerify, above given is the pact contract version that is being used

vijay.chinthala
2019-11-28 00:45
```$./gradlew pactVerify -Ppact.verifier.publishResults=true```

vijay.chinthala
2019-11-28 00:45
this is the command I ran

uglyog
2019-11-28 00:47
I think she meant in the matrix view of the pact broker. Every time you run the pact verify command, it will create a new row

vijay.chinthala
2019-11-28 00:48
I think that is fine for the version I am verifying, but it is also creating an entry for other versions


vijay.chinthala
2019-11-28 00:49
it should not be updating for version/1.0.4? isn't it the right expectation?

uglyog
2019-11-28 00:50
No, because the pact file is the same for all the versions

vijay.chinthala
2019-11-28 00:51
ok I see, I will make a change to the pact contract and will test it

vijay.chinthala
2019-11-28 00:52
thank you both for helping me to solve these issues, have a great thanks giving holidays :slightly_smiling_face:

bethskurrie
2019-11-28 01:01
The verification is attached to the underlying pact content. If you have two pacts with the same content, and you verify one of them, other other is also verified.

bethskurrie
2019-11-28 01:02
Technically, both pact publications point to the same pact version, and the single verification is attached to the single pact version, but when you expand that out into a table, you get two rows, because it is a many to many relationship.


artemabezruchko
2019-11-28 17:00
has joined #pact-jvm

hande.sagar
2019-11-28 17:18
Hi I have updated the pact-jvm-provider-maven to 4.0.3 and now I can see branch name and commit no.

hande.sagar
2019-11-28 17:19
I am using such command sh "mvn clean test -Dpactbroker.host=pact-broker.pact-broker -Dpact.verifier.publishResults=true -Dpact.provider.version=${gitCommit} -Dpact.tag=${branchName}"

hande.sagar
2019-11-28 17:19
but now problem is I am able to see branch name only for specific commit

hande.sagar
2019-11-28 17:20
for other commit numbers I dont know why it is not showing branch name

uglyog
2019-11-28 20:58
Best to raise an issue for it, posts on slack will get lost

uglyog
2019-11-28 21:00
It will only show the branch name associated with the commit for the result that is being published

hande.sagar
2019-12-01 12:07
as you can see , it doesnt display tag name every time , why it is?

sabil.beladri
2019-12-02 16:16
Hi, we're wondering here if anyone managed to work out a tool on the consumer side to parse & convert a JSON message to its lambda DSL code counterpart thanks for keeping me posted if so!

c.talek
2019-12-02 19:27
has joined #pact-jvm

c.talek
2019-12-04 15:00
@c.talek has left the channel

paul.simms
2019-12-04 16:12
has joined #pact-jvm

m.kwiecien
2019-12-04 17:47
Hi. I have problem with matchers. When I use value matcher in pact written on consumer ex. *stringValue(), .booleanValue()* I don't have proper validation on provider (my test passes even if provider doesn't have required state and return different value). I have noticed that in pact file that is created there is only *matching rule* for fields I used ex .stringType() matcher not for stringValue(). Example of response body I have where "avaliable" *boolenValue is not checked on provider verification*: ```DslPart responseBody = LambdaDsl.newJsonBody((body) -> { body .minArrayLike("addresses", 1, (array) -> { array.object("address", (address) -> { address .stringType("postcode", availablePostcode); }) .object("availability", (availability) -> { availability .booleanValue("available", true); }); }); }) .build();```

uglyog
2019-12-04 20:59
Those functions don?t add matches because the value will be checked that it is equal to the provided value

uglyog
2019-12-04 21:00
This is done by default by the pact verifier

yamuna.rani
2019-12-05 09:09
has joined #pact-jvm

yamuna.rani
2019-12-05 09:10
Hi Team..Can I pass the dynamic values to @Pact annotation? @Pact(provider = "Profile_Provider", consumer = "Profile_Consumer") I want to set the provider and consumer name from my property file. Is it possible ?

uglyog
2019-12-05 10:16
No, the `@Pact` annotation expects static values

m.kwiecien
2019-12-05 16:52
I used pact-jvm-provider-gradle and I got body match although I see in response from my provider when verifying pact that boolean value is false in case I expected true.

uglyog
2019-12-05 20:46
If you run with debug level logs, using the -d parameter, you should be able to see what the verifier is doing

hande.sagar
2019-12-06 09:21
I want to see tag name on pact provider and using below mvn command

hande.sagar
2019-12-06 09:21
mvn -Dtest=ClearingCaseDefinedPactTest clean test -Dpactbroker.host=http://kube-pact -Dpact.verifier.publishResults=true -Dpact.provider.version=9d0724ea6d5df37fcd3f5e97cb746de056297e29 -Dpact.tag=feature/FMCLS-338-pact-refinement

hande.sagar
2019-12-06 09:21
still I dont see tag name

hande.sagar
2019-12-06 09:21
could you please help me

justaburneremailforso
2019-12-06 16:28
I haven't tried it with mvn yet but I can get it to work by using the create version tag script mentioned here: https://github.com/pact-foundation/pact_broker-client/blob/master/README.md

ivangsa
2019-12-09 14:55
has joined #pact-jvm

justaburneremailforso
2019-12-10 09:25
Hello, I am trying to get mvn clean test to work with our broker. For some reason when I point to a broker with authentication switched on, I am getting a "Request to path '/' failed with response http/1.1 400 bad request" even when I use credentials. What dependencies do I need in my pom? The pact-junit example I was looking at seems to be based on gradle and not maven.

hande.sagar
2019-12-10 10:13
need some help

hande.sagar
2019-12-10 10:13
we can create tag using pact cli command - pact-broker create-version-tag -a clearing-events -b http://kube-pact -e a921988c106f6cfa8f19941656ff499d8a399b21 -t develop

hande.sagar
2019-12-10 10:13
do we have option to create such tag using mvn command

justaburneremailforso
2019-12-10 11:54
Got this resolved. We needed to set the scheme as Https and the full hostname in the @PactBroker annotation section of the junit class. Previously we were using a shortened hostname and not setting the scheme as anything. We are still using the @PactBrokerAuth authentication piece.

hande.sagar
2019-12-10 14:45
we can create tag using pact cli command - pact-broker create-version-tag -a clearing-events -b http://kube-pact -e a921988c106f6cfa8f19941656ff499d8a399b21 -t develop do we have option to create such tag using mvn command ?

nathan.deamer
2019-12-12 13:04
Does anyone have an example for a consumer PACT expecting a ZonedDateTime in the response?

hande.sagar
2019-12-12 14:44
we can create tag using pact cli command - pact-broker create-version-tag -a clearing-events -b http://kube-pact -e a921988c106f6cfa8f19941656ff499d8a399b21 -t develop do we have option to create such tag using mvn command ?

bart.schotten
2019-12-12 14:48
Sagar, have you read my email? I think we can conclude that it simply won't work like this. Please just use the workaround.

sam774
2019-12-13 20:28
has joined #pact-jvm

hande.sagar
2019-12-14 05:10
Hi Bart, yes I will set up an short call to understand it in better way... Thank you

anddreiu
2019-12-17 08:51
Hi @uglyog. Do you know when there will be a new release for pact-jvm? There are some nice fixes which were not released yet. Many thanks!

uglyog
2019-12-17 09:11
I?ll see if I can organise a release this week, other wise I?m away until mid January

anddreiu
2019-12-17 09:40
Ok, that would be very useful. Thanks a lot. And enjoy your holiday!

sam774
2019-12-17 11:43
I'm using pact-jvm with a spring boot test, and I'm currently seeing the following error: ```java.lang.NoClassDefFoundError: kotlin/TypeCastException at http://java.net.URLClassLoader.findClass``` Versions I'm using: pact-jvm 4.0.3 spring-boot 2.1.11-RELEASE kotlin (overridden) 1.3.61 I can't copy over the test exactly but it looks like, in short: ```@ExtendWith(PactConsumerTestExt.class) @SpringBootTest(classes=MyClassToTest.class) @AutoConfigureWebClient @PactTestFor(providerName = "provider", port = "8081") class ConsumerTest { @Autowired MyClassToTest client; @Pact(consumer = "consumer") public RequestResponsePact thePact(PactDslWithProvider builder) { return builder.given("a state") .uponReceiving("a thing") .path("/") .method("GET") .withRespondWith() .status(200) .body(... clipped ...) .toPact(); } @Test @PactTestFor(pactMethod = "thePact") public void myTest() { client.getTheThing(); } }``` So nothing out the ordinary. Anyone got any ideas what could be up?

sam774
2019-12-17 11:44
FWIW - Prior to manually adding in a kotlin version override in my pom, bumping from 1.2.something -> 1.3, the spring boot app was starting up, making the request and there was a NoSuchMethodError from the pact-jvm kotlin code thrown. So I don't think the problem is with the Spring Boot app I've written

uglyog
2019-12-17 22:26
I can't see anything wrong with your test class. Maybe raise an issue and provide the full stack trace and debug logs

loveshjain88
2019-12-18 01:54
has joined #pact-jvm

loveshjain88
2019-12-18 01:56
Hi All, I am using Pact JVM and trying to add header for every request when provider verifies it I added @TargetRequestFilter according to https://github.com/DiUS/pact-jvm/tree/master/provider/pact-jvm-provider-junit#modifying-the-requests-before-they-are-sent-version-323245 but it is not getting called?

sam774
2019-12-18 08:09
Updating to 4.0.4 fixed this :party_parrot:

uglyog
2019-12-19 01:14
@loveshjain88 are you sure it is not being called? The examples from the Pact-JVM project work

uglyog
2019-12-19 01:17
Can you provide your test class?

loveshjain88
2019-12-19 02:08
@PactBroker @Provider("testConsumer") @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @TestPropertySource(locations = "classpath:application-pact.yml") class TestClass { @LocalServerPort private int serverPort; @MockBean private ApplicationsController ApplicationsController; @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void testTemplate(PactVerificationContext context, HttpRequest httpRequest) { httpRequest.addHeader("Authorisation", "test"); context.verifyInteraction(); }

loveshjain88
2019-12-19 02:10
we are using Junit5 and Spring boot

loveshjain88
2019-12-19 02:10
and Mockmvc

uglyog
2019-12-19 02:12
@TargetRequestFilter doesn't work with MockMVC

uglyog
2019-12-19 02:12
With MockMVC, there is no actual request

loveshjain88
2019-12-19 02:15
I thought putting in the method annotated with @TestTemplate should work with Mockmvc and Junt5

loveshjain88
2019-12-19 02:15
as per the example

loveshjain88
2019-12-19 02:16
~@BeforeEach void setup(PactVerificationContext context) throws Exception { context.setTarget(new HttpTestTarget("localhost", serverPort)); } @State("a valid state") void validApplicationRequest() { when(applicationsController.createApplication( any(ApplicationRequest.class))). thenReturn(new ResponseEntity<>( new ApplicationResponse( UUID.randomUUID() )~

uglyog
2019-12-19 02:28
Oh, wait, you're not using MockMVC, you're using the HTTP to the actual provider

loveshjain88
2019-12-19 02:42
I am actually mocking the controller. I want to add the Authorisation header to every request? How can I achieve that?

uglyog
2019-12-19 02:43
With JUnit5, the correct way is to inject the request as you're example shows

loveshjain88
2019-12-19 02:45
but unfortunately its not working or else I am missing something?

uglyog
2019-12-19 02:45
What makes you think the header is not being set? I've just tested it, and it definitely works


uglyog
2019-12-19 02:47
If I change line 45 to ```request.addHeader("X-ContractTest", "false");``` the test fails with ```----------------------------------------------------------------------------------------------------------------------- | Closest stub | Request | ----------------------------------------------------------------------------------------------------------------------- | GET | GET /data | /data?ticketId=0000 | X-ContractTest: true | X-ContractTest: false <<<<< Header does not match | Query: ticketId [matches] 0000|1234|99987 | ticketId: 0000 | | -----------------------------------------------------------------------------------------------------------------------```

loveshjain88
2019-12-19 02:51
The request filter still shows null

uglyog
2019-12-19 02:52
requestFilter is not used by the JUnit5 library

loveshjain88
2019-12-19 02:55
If I check the header group, I can see the Authorisation header added

loveshjain88
2019-12-19 02:55
is that correct?

uglyog
2019-12-19 02:56
It looks correct to me

loveshjain88
2019-12-19 04:10
Thanks. It worked

loveshjain88
2019-12-19 04:10
There was something wrong in the controller implementation

sam774
2019-12-19 15:18
Hey - using pact-jvm is there a way to assert a json response contains a specific date format? Specifically YYYY-MM-dd. I was hoping that `date()` would do the trick, and without any further params generates the following matcher: ```{ "match": "date", "date": "YYYY-MM-dd" }``` But when I then run pact provider verification, I get an error because the generated value 2000-01-31 doesn't match exactly what's returned from the provider. I suspect that match: type is what I need, and was wondering if there's a better way than using a string matcher with a regex for YYYY-MM-dd formatted dates

uglyog
2019-12-19 21:41
The date matcher will try parse the string using the format pattern. What is the provider sending? Does it include timezones?

sam774
2019-12-19 22:20
The provider is sending "2019-12-19" without any timezone data.

uglyog
2019-12-19 22:30
Hmm, that should parse correctly then

uglyog
2019-12-19 22:31
what version of Pact-JVM are you using?

uglyog
2019-12-19 22:34
Also, can you check debug level logs? Those will show what the verifier is doing

sam774
2019-12-19 23:05
Will do in the morning! Using 4.0.4. thanks a lot :grin:

gaurav.singh55
2019-12-20 03:30
has joined #pact-jvm

sumeshs572
2019-12-21 01:17
has joined #pact-jvm

taisedias
2019-12-22 21:53
has joined #pact-jvm

abhilash.giridharan
2019-12-24 06:58
has joined #pact-jvm

mui_ume
2019-12-27 14:32
Hi I?m getting this error when I run my pact provider test - java.lang.NumberFormatException: null at java.base/java.lang.Integer.parseInt(Integer.java:620) at java.base/java.lang.Integer.parseInt(Integer.java:776) at au.com.dius.pact.provider.spring.SpringInteractionRunner.setupTargetForInteraction(SpringInteractionRunner.kt:103) at au.com.dius.pact.provider.junit.InteractionRunner$interactionBlock$statement$1.evaluate(InteractionRunner.kt:203)

mui_ume
2019-12-27 14:33
My pact test code snippet - import au.com.dius.pact.provider.junit.Provider; import au.com.dius.pact.provider.junit.State; import au.com.dius.pact.provider.junit.loader.PactFolder; import au.com.dius.pact.provider.junit.target.Target; import au.com.dius.pact.provider.junit.target.TestTarget; import au.com.dius.pact.provider.spring.SpringRestPactRunner; import au.com.dius.pact.provider.spring.target.SpringBootHttpTarget; import com.taiger.admin.AdminApp; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.TestPropertySource; @RunWith(SpringRestPactRunner.class) @Provider("Provider") @PactFolder("src/test/resources/pacts") @SpringBootTest(classes = AdminApp.class) public class AuthenticatePactTest { @TestTarget public final Target target = new SpringBootHttpTarget(); @State("Authenticate with valid clientId") public void authenticateTest() { System.out.println("Verifying AuthenticateTest"); } }

mui_ume
2019-12-27 14:34
My pact file in Json "body": { "accessToken": "xxxxerfhggtgggf", "timeLeftRefreshThresholdMs": 1800000, "authenticationErrorMsg": null },

sridevi_akshayapatra2
2019-12-30 17:26
has joined #pact-jvm

wesleythomaswilliams
2020-01-02 10:55
has joined #pact-jvm

swaroopshere
2020-01-03 00:28
has joined #pact-jvm

swaroopshere
2020-01-03 00:29
hello! im wondering if there is support for 'valueFromProviderState' usage in pact-jvm-consumer-java8 library? I am trying to define a json body in a POST request where I would like to inject certain string values while running the test on provider side.

gerrymcgovern
2020-01-03 15:43
has joined #pact-jvm

iaroslav.liashenko
2020-01-03 16:05
has joined #pact-jvm

brent_jackson
2020-01-03 17:01
has joined #pact-jvm

wesleythomaswilliams
2020-01-07 14:39
Hi all, quick question, using pact with junit5 and just want to double check the latest version of things. I have `pact-junit.version = 3.6.14` and the version of `pact-jvm-provider-maven = 4.0.0`

uglyog
2020-01-08 06:48
You should use the same major version. You can find the latest version at the pact-jvm GitHub page. I think it is 4.0.3

sam774
2020-01-08 10:41
I'm having some issues with pact jvm 4.0.4, where provider verification is failing. The following error is present in the logs: ```line 1:0 token recognition error at: 'nu' line 1:2 token recognition error at 'll' line 1:4 mismatched input '<EOF>' expecting {'next', 'last', 'now', 'today', 'yesterday', 'tomorrow', '+', '-'}``` That repeats another two times, which I suspect is because there's three `date` entries in the Pact. It's generated according to Pact spec v3.0.0, and the date matchers all look like this: ```"$.paidDate": { "matchers": [ { "match": "date", "date": "yyyy-MM-dd" } ], "combine": "AND" }``` and ```"generators": { "body": { ... clipped ... "$.paidDate": { "type": "Date", "format": "yyyy-MM-dd", "expression": "null" } ... clipped ... } }``` From the debug logs while I perform provider verification: ```method: POST path: <clipped> query: {} headers: {Content-Type=[application/json;charset=UTF-8]} matchers: MatchingRules(rules={header=<clipped>, body=Category(name=body, matchingRules={$.paidDate=MatchingRuleGrouyp(rules=[DateMatcher(format=yyyy-MM-dd)], ruleLogic=AND), <others>)}) generators: Generators(categories={BODY]{$.paidDate=DateGenerator(format=yyyy-MM-dd, expression=null), <others>}) body: PRESENT({"paidDate":"2020-01-08",<others>}) Received response: HTTP/1.1 400``` Anyone have any ideas what may be causing this?

sam774
2020-01-08 10:43
fwiw the dates here are in the body of the POST request

abubics
2020-01-08 23:29
nfi, but `"expression":"null"` seems hinky :thinking_face:

sam774
2020-01-09 06:52
It's auto-generated but I manually removed that and it made no difference

muppasaikarthik964
2020-01-09 09:28
has joined #pact-jvm

wesleythomaswilliams
2020-01-09 15:47
Thanks

wesleythomaswilliams
2020-01-09 17:06
Hi all, I'm trying to get pact-jvm and pact flow working together in a maven, junit5 spring environment. I've managed to publish my pact from my consumer to pact flow with `mvn pact:publish` . However, on the provider side I can't get verification working using maven. I can run my provider test directly using junit and it successfully verified a local pact or a pact stored on pact flow, but I can't get `mvn pact:verify` to work for either. ```@ExtendWith({ SpringExtension.class, MockitoExtension.class }) @Provider("wes_service") @EnableAutoConfiguration @SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = { wesSearchControllerV1.class }) @TestPropertySource(properties = "server.port=1337") @PactBroker( host = "http://wesley.pact.dius.com.au", scheme = "https", port = "443", authentication = @PactBrokerAuth(token = "<token>")) public class PactProviderTest { @LocalServerPort private int port; @MockBean private wesWrapperService wesWrapperService; @MockBean private ValidationService validationService; @BeforeEach void setupTestTarget(PactVerificationContext context) { context.setTarget(new HttpTestTarget("localhost", port, "/")); } @Testweslate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactVerificationTestweslate(PactVerificationContext context) { context.verifyInteraction(); } @State({"provider returns a wes"}) public void findByIdentifier_get() { // State final Identifier eanIdentifier = Identifier.builder() .alias("<key>") .value("<value>") .build(); final wesWrapper wesWrapper = wesWrapper.builder() .wes("<value>") .identifiers(Stream.of( eanIdentifier ).collect(Collectors.toSet())) .aliases(Stream.of( "<value>" ).collect(Collectors.toSet())) .build(); when(wesWrapperService.findByIdentifierAlias(eanIdentifier.getAlias(), eanIdentifier.getFirstValue())).thenReturn(wesWrapper); } }``` Pom ```<!-- Pact --> <plugin> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>4.0.4</version> <configuration> <pactBrokerUrl>https://wesley.pact.dius.com.au</pactBrokerUrl> <pactBrokerToken>mytoken</pactBrokerToken> <pactBrokerAuthenticationScheme>Bearer</pactBrokerAuthenticationScheme> <serviceProviders> <serviceProvider> <name>sain_service</name> <protocol>http</protocol> <host>localhost</host> <port>1337</port> <path>/</path> </serviceProvider> </serviceProviders> </configuration> </plugin>``` Result ```Verifying a pact between consumer_service and provider_service [from Pact Broker https://wesley.pact.dius.com.au/pacts/provider/provider_service/consumer/consumer_service/version/0.0.4] Given provider returns a thing WARNING: State Change ignored as there is no stateChange URL a request to get a thing Request Failed - Connect to localhost:1337 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused) [WARNING] Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true') Failures: 0) Verifying a pact between consumer_service and provider_service - a request to get a thing Given provider returns a thing Connect to localhost:1337 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)```

rikeshgohil
2020-01-10 10:33
has joined #pact-jvm

wesleythomaswilliams
2020-01-13 12:08
@uglyog If you have any bright ideas on what I might be missing here, they'd be much appreciated. I've been continuing to work on a solution, but not getting far. I'm wondering if it's related to the my dependencies and runner. My pom now has these dependencies: ``` <dependency> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-junit5</artifactId> <version>${pact.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-spring</artifactId> <version>${pact.version}</version> <scope>test</scope> </dependency>``` And I've tried playing around with the annotations in my provider test. Latest is: ```@RunWith(SpringRestPactRunner.class) @Provider("sain_service") @EnableAutoConfiguration @SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = { SainSearchControllerV1.class }, properties = { "server.port=1337" }) @PactBroker( host = "http://wesley.pact.dius.com.au", scheme = "https", port = "443", authentication = @PactBrokerAuth(token = "fTXDVdhGOlKunW_wIPDn3w"))``` But still can't get a connection to the provider when run via Maven (running via junit still works fine). My knowledge of Spring and Maven are limited as it's all quite new to me.

anders
2020-01-13 17:58
has joined #pact-jvm

anders
2020-01-13 17:59
Hello. I am trying to specify (in Java) an expectation in a pact interaction that a response should contain an object with an ISO8601-formatted date-time. `io.pactfoundation.consumer.dsl.LambdaDslObject` is the relevant class, and it contains several alternatives, but I can't figure out which is correct. Firstly, there is the `dateTimeExpression` method, which takes a `String expression` as its second argument. I've been trying to figure out how this method works and find some documentation/examples of the possible values of `expression`, with no great success. I traced the source code until I reached `parseDateExpression` in https://github.com/DiUS/pact-jvm/blob/master/core/model/src/main/kotlin/au/com/dius/pact/core/model/generators/DateExpression.kt before I gave up, because I'm not about to start deciphering an actual parser. Can anyone here shed some light on what the `expression` parameter is and how it's meant to be used? (And an update to the documentation would also be useful for the next person.) Secondly, what is the difference between the `datetimeExpression` and `timestamp` methods on `LambdaDslObject`? When do you use which of the two?

kevinkontcheu
2020-01-13 22:37
has joined #pact-jvm

uglyog
2020-01-13 23:22
`dateTimeExpression` is for provider state injected values. See https://blog.pactflow.io/injecting-values-from-provider-states/ for more information. You should use `timestamp` for date-time values.

uglyog
2020-01-13 23:34
The JUnit Spring test framework is starting your provider before running your test. If you want to use the Maven plugin to run the verification, you need to have your provider started before it runs. One way of doing that is to use the integration test phase, which has a pre- and post- phase that can be used to start and stop your provider. You'll ned to work out how to bind the pact plugin to the integration test phase and find a plugin that can start your provider in the pre-integration-test phase. I would recommend using JUnit tests, though. You don't have to worry about starting and stopping the provider then.

wesleythomaswilliams
2020-01-14 09:27
@uglyog Apologies if I misunderstand this, but are you saying that the use of SpringBootTest is the main issue here because of the order of execution?

kevinkontcheu
2020-01-14 14:01
Hi there please i need help

kevinkontcheu
2020-01-14 14:02
```return builder .given("first state") .uponReceiving("GET Request from consumer") .path(GEOFENCE_PATH) .method("GET") .willRespondWith() .status(200) .headers(headers) .body(".... ") .given("new state") .uponReceiving("POST Request from consumer") .path(GEOFENCE_PATH) .method("POST") .willRespondWith() .status(200) .headers(headers) .body(".....").toPact();```

kevinkontcheu
2020-01-14 14:04
I'm trying to write some Tests with Pact but i have the following problem: When i just have one Interaction it's working well but when i try to add one more Transaction the tests are falling apart and i have this: http://au.com.dius.pact.consumer.PactMismatchesException: http://au.com.dius.pact.consumer.PactMismatchesException: The following requests were not received: method: GET path: /api/XX/locations/1234/geofences query: [:] headers: [:] matchers: MatchingRules(rules=[path:Category(name=path, matchingRules={})]) generators: Generators(categories={}) body: OptionalBody(state=MISSING, value=null)

kevinkontcheu
2020-01-14 14:05
Here are the test ```@Test @PactVerification() public void getGeofenceByLocationId_shouldReturn200WithProperHeaderAndBody() { // when ResponseEntity<GeofenceGetDTO> response = new RestTemplate().getForEntity( mockProvider.getUrl()+GEOFENCE_PATH, GeofenceGetDTO.class ); // then assertEquals(HttpStatus.OK,response.getStatusCode()); }``` Please can someone tell me what si wrong with this? Thanks

kevinkontcheu
2020-01-14 14:06
```@Rule public PactProviderRuleMk2 mockProvider = new PactProviderRuleMk2("provider", "localhost",8888, this);``` I',m using the Rule annotation to start the mockserver

wesleythomaswilliams
2020-01-14 15:34
Chatting with our dev team here, it seems my desire to execute with `mvn pact:verify` was unnecessary. The test executes perfectly as part of our unit tests executed with `mvn clean install` . Thanks for the assistance, I'm sure I'll have more questions as we move forward. Once we've got rest working, we'll be trying pact with kafka.

s1apped
2020-01-14 21:43
Hi. After publishing contract to pact-broker I'm seeing below message `Could not parse the following content to a Pact due to TypeError no implicit conversion of String into Integer, showing raw content instead` When I try to run provider verification it fails with below but when I run locally using @PactFolder everything works. ```http://au.com.dius.pact.provider.junit.MissingStateChangeMethod``` Looks like there is some issue with regex / matchPath ```return builder .given("This is valid regex") .uponReceiving("Some test request") .matchPath("/test/1/regex/(this|that)") .method("GET") .willRespondWith() .status(200) .toPact();``` Above will fail with error but when I replace matchPath with path it will work ```.path("/test/1/regex/this")``` Anyone have any ideas what may be causing this? Thanks

uglyog
2020-01-14 22:27
You've added a second interaction for a POST request, but you test is only making the GET request. So the mock server is failing the test because it did not get all the expected requests.

uglyog
2020-01-14 22:30
How are you running the verification? Using JUnit or Gradle/Maven?

s1apped
2020-01-15 06:39
using junit


wesleythomaswilliams
2020-01-15 09:35
I get the following message: ```Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true')```

s1apped
2020-01-15 11:36
more precise junit5

antonello
2020-01-15 17:27
```<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <redirectTestOutputToFile>true</redirectTestOutputToFile> <testSourceDirectory>src/test/java</testSourceDirectory> <systemPropertyVariables> <pact.provider.version>${pact.pacticipantVersion}</pact.provider.version> <pact.verifier.publishResults>false</pact.verifier.publishResults> <pact.provider.version.trimSnapshot>true</pact.provider.version.trimSnapshot> </systemPropertyVariables> </configuration> </plugin>```

antonello
2020-01-15 17:29
This works for us

swaroopshere
2020-01-15 22:58
hello, is there a configuration to enable debug logging in tests written with pact-jvm-consumer-junit5. Im currently running into errors while executing the contract on consumer side and would like to debug it

swaroopshere
2020-01-15 23:04
oh turns out setting ```http://logging.level.au.com.dius.pact=DEBUG``` in application.properties worked

uglyog
2020-01-15 23:26
The `MissingStateChangeMethod` exception is normally thrown because you don't have a matching state change handler for your provider state `"This is valid regex"`. See https://github.com/DiUS/pact-jvm/blob/master/provider/pact-jvm-provider-junit/README.md#provider-state-callback-methods

uglyog
2020-01-15 23:29
You should also use the version of match path that takes an actual example path, i.e. `.matchPath("/test/1/regex/(this|that)", "/test/1/regex/this")`

shero86
2020-01-16 11:23
has joined #pact-jvm

s1apped
2020-01-16 14:41
I have @State set for every provider. Interesting thing is when I run test manually with @PactFolder everything works but gradle clean build test fails with http://au.com.dius.pact.provider.junit.MissingStateChangeMethod and in @TestTemplate during ```context.verifyInteraction();``` I'm really confused

alan.nichols
2020-01-16 15:40
has joined #pact-jvm

alan.nichols
2020-01-16 15:47
Hi all. Hoping to get some guidance on creating a PACT for an android application. When creating one for an iOS app, I can set it to type match everything in the body, meaning that I can just read in the body as a JSON blob. I see the same in some PACT docs here - https://docs.pact.io/getting_started/matching#type-matching. Is there a similar mechanism in the jvm version? Sorry if I've missed it when reading the docs!

wesleythomaswilliams
2020-01-16 17:49
Thanks @antonello, unfortunately that doesn't seem to work for me. What does work is including this in my provider tests: ``` @BeforeAll static void beforeAll() { System.setProperty("pact.verifier.publishResults", "true"); System.setProperty("pact.provider.version", "0.0.1"); }``` This isn't good though as really these need to be global settings and I don't want the provider version set manually. What am I missing @uglyog?

uglyog
2020-01-16 22:28
Do you want to just match the whole body, meaning the structure must match but the values don't need to?

fox_rul
2020-01-17 03:11
has joined #pact-jvm

s1apped
2020-01-17 08:59
looks like my issues is having state change methods in multiple classes...

alan.nichols
2020-01-17 09:50
Exactly yes. Sorry, that would have been a much better way of explaining it.

brook
2020-01-17 17:08
has joined #pact-jvm

uglyog
2020-01-18 23:20
Pact-JVM supports type matching, but there is no easy way using the DSLs to provide a JSON document and specify it should be matched by type. Maybe raise an issue at the GIthub project for this enhancement.

ssong
2020-01-20 02:17
has joined #pact-jvm

ssong
2020-01-20 02:19
Hi All, I have a question regarding to the provider Pact test. I'm using JUnit5, based on the samples provided from the github, I need to have `@PactFolder` annotation for the test class. Is there anyway I can have this value configured in the build.gradle file?

uglyog
2020-01-20 02:26
`@PactFolder` values can only be set at compile time

uglyog
2020-01-20 02:27
You should be able to create your own loader to do what you need

ssong
2020-01-20 02:36
Do I need to pass the loader to my test? how does that work?


ssong
2020-01-20 02:40
Got it. Thanks!

w.everse
2020-01-20 18:36
has joined #pact-jvm

antonello
2020-01-21 08:17
This is ?us? by the way!

uglyog
2020-01-21 23:19
Might be class path being different when run with Gradle. How where you running it when you test manually with @PactFolder?

nerea.tamayo
2020-01-22 08:41
has joined #pact-jvm

nerea.tamayo
2020-01-22 08:42
Hi! I'm trying to implement CDC with Pact, and I have a question....For verifying Pact (JVM) from the provider side, is it necessary that the provider is running?

jgfarias42
2020-01-22 09:51
has joined #pact-jvm

antonello
2020-01-22 14:20
@alessio.paciello and @emanuele.ivaldi have found that the property `pact.filter.consumers` does not seem to be applied when the entry point is junit.

emanuele.ivaldi
2020-01-22 14:20
has joined #pact-jvm

antonello
2020-01-22 14:58
However, there seems to be `pactbroker.consumers` , which works

antonello
2020-01-22 15:01
but it?s not documented :slightly_smiling_face:

sabil.beladri
2020-01-22 18:31
Hi, any hint on how to get rid of this failure I get from CI? `HeaderMismatch(headerKey=User-Agent, expected=Apache-HttpClient/4.5.5 (Java/1.8.0_202-release), actual=Apache-HttpClient/4.5.5 (Java/1.8.0_222)` I hardcoded the expected one in the contract definition (so it matches on my cpu: `.headers("User-Agent", "Apache-HttpClient/4.5.5 (Java/1.8.0_202-release)")` ) but I'd better extract this dynamically (so it matches on any cpu). Thanks in advance!

antonello
2020-01-22 22:14
@uglyog When you get a chance it would be good to get your input on this!

uglyog
2020-01-22 22:16
Yeah, I saw that one come through. Should be a simple fix

uglyog
2020-01-23 00:19
I don't think that the user agent header would be an important thing to add to your contract. It will change based on the HTTP client accessing your provider.

uglyog
2020-01-23 00:19
This will need to be fixed then

sabil.beladri
2020-01-23 07:39
Thanks for your feedback! It's clearer now the MockMVC provider side will have to handle this (otherwise I'm getting error upon trying to get a response with Spring), I wasn't too sure either to add it on consumer side or do some trickery on the provider side.

ankit992
2020-01-23 17:04
has joined #pact-jvm

antonello
2020-01-24 07:41
@uglyog would it possible to do a release of pact-jvm at some point soon?

uglyog
2020-01-24 09:03
Definitely, I?ll do one this weekend

sabil.beladri
2020-01-24 12:23
Hi, I'm back with a related doubt: how can we add headers (such as `user-agent`) following the MockMvc test examples provided in github repo [1] ? This test [2] seems to provide a way to inject headers, but it's building the request from scratch instead of retrieving it from pact broker (as in github readme examples). For now, we removed the user-agent header from the consumer declaration as we agree it's not needed there. But then we also had to make it *optional* from the controller to be able to validate the contract, since it's not clear how to inject this on provider test side :sweat: It's quite ok for user-agent but some other headers (e.g. locale) may be *mandatory* for the controller under test and different for each client running the test. So they would be excluded from the contract declaration and still would be needed for validation. Thanks for sharing your point of view on this topic! 1: https://github.com/DiUS/pact-jvm/tree/master/provider/pact-jvm-provider-spring 2: https://github.com/DiUS/pact-jvm/blob/master/provider/pact-jvm-provider-spring/src/test/groovy/au/com/dius/pact/provider/spring/MvcProviderVerifierSpec.groovy

balthasarbiedermann
2020-01-24 13:01
I'm using pat-jvm with Spring Boot. I've just upgraded to Spring Boot 2.2.x and it seems like the Content-Type of the HTTP client changed from `application/json;charset=UTF-8` to `application/json`, which broke my contract test. I use a `PactDslJsonBody` and did not specify the `COntent-Type` in my pact at all. It looks like pact is implicitly expecting the `application/json;charset=UTF-8` content type. Can I change the pact definition to accept both?

g.van.vliet
2020-01-24 13:13
has joined #pact-jvm

antonello
2020-01-24 14:52
thanks!

swaroopshere
2020-01-24 23:52
Is it possible to define a Bodymatcher for Content-type "text/json"? In my Pact test, I run into this issue thats described in the foll logline - ```15:37:01.706 [Thread-15 ] DEBUG [-,,] [,] DEBUG a.c.d.p.c.m.Matching : No matcher for text/json, using equality : 15:37:01.707 [Thread-15 ] DEBUG [-,,] [,] DEBUG a.c.d.p.c.m.RequestMatching : Request mismatch: [BodyMismatch(expected=[B@64dbf925, actual=[B@5f40ca8, mismatch=Actual body '[B@5f40ca8' is not equal to the expected body '[B@64dbf925', path=/, diff=null)] : ``` I tried to look into the code in RequestMatching, Matching and MatchingConfig classes (as much as Intellij decompiler would let me look into), and it seems that in 'Matching' class, the code resorts to byte comparison when no matcher is found, which will obviously fail.

swaroopshere
2020-01-24 23:55
if I switch to 'application/json' Content-type, then I run into a different problem - ```[BodyMismatch(expected= ... (clipped text) mismatch=Type mismatch: Expected Map but received Primitive "{\"requestType\":``` Ive stripped out the payload, but it looks like the expected object is a json object, whereas the actual object is also a json object but in a String with escaped \" characters

uglyog
2020-01-25 04:45
Just set the content type to `application/json` and it will accept both

uglyog
2020-01-25 04:47
Looks like an issue with your implementation. The body should not be encoded as a String for JSON payloads

ankit992
2020-01-25 04:55
Has anyone figured out a way to use mockwebserver in android to generate the pact files? I need this to be able to run the UI tests of android on the base of the pact files generated

swaroopshere
2020-01-25 04:56
yeah turns out it was an implementation issue.

ankit992
2020-01-25 04:56
Currently we?re using unit tests to generate pacts, after that we start a pact server to run the urls on localhost and our ui tests from emulator hit the system on localhost to fill the loop

swaroopshere
2020-01-25 05:01
Does pact-jvm DSL support timestamp in 'milliseconds since epoch' format?


uglyog
2020-01-25 05:03
But 'milliseconds since epoch' is just an integer number

swaroopshere
2020-01-25 05:05
thank you @uglyog. I did use numberType in my definition for body. It seems the numberType does not really do type matching on consumer side? That timestamp field is not something I have control over, the system generates it, but I would like to ensure that it exists in the body, regardless of the value

uglyog
2020-01-25 05:07
It should do type matching on the consumer side. If you specify it as integerType, and you pass a string that will fail.

uglyog
2020-01-25 05:09
@abubics might be able to answer this one

swaroopshere
2020-01-25 05:14
hmm, here is a part of my definition ```.object() .numberType("joinedTimestamp") ....``` but when the test executes, it throws this error, along with a few other errors ```diff={ - "joinedTimestamp": 100, + "joinedTimestamp": 1579929027471, ... ...``` does this indicate that the type matching isnt happening?

uglyog
2020-01-25 05:19
Not necessarily, what is the actual message? That diff is because it is using a random value as you have not provided an example value, e.g. `.numberType("joinedTimestamp", 100)`

swaroopshere
2020-01-25 05:23
this is the message - ```21:10:28.137 [Thread-15 ] DEBUG [-,,] [,] DEBUG a.c.d.p.c.m.RequestMatching : Request mismatch: [BodyMismatch(expected="string", actual=null, mismatch=Expected null (JsonNull) to be the same type as "string" (JsonPrimitive), path=$.requestId, diff=null), BodyMismatch(expected={"joinedTimestamp":100,"app":"phone","notificationDelay":10000,"role":"Role","participantDevice":null,"subject":"005xx000001Svyg","highWatermark":null,"persistedId":null,"context":"Context","doNotReceiveOwnMessagesBack":false}, actual={"joinedTimestamp":1579929027471,"app":"phone","leftTimestamp":null,"notificationDelay":10000,"role":"Role","participantDevice":null,"subject":"005xx000001Svyg","highWatermark":null,"context":"Context","persistedId":null,"doNotReceiveOwnMessagesBack":false,"lastActiveTimestamp":null}, mismatch=Expected a Map with 10 elements but received 12 elements, path=$.participants.0, diff={ - "joinedTimestamp": 100, + "joinedTimestamp": 1579929027471, "app": "phone", + "leftTimestamp": null, "notificationDelay": 10000, "highWatermark": null, - "persistedId": null, "context": "Context", - "doNotReceiveOwnMessagesBack": false + "persistedId": null, + "doNotReceiveOwnMessagesBack": false, + "lastActiveTimestamp": null })] :```

uglyog
2020-01-25 05:26
The actual problem is `$.requestId` is null: Expected null (JsonNull) to be the same type as "string" (JsonPrimitive)

swaroopshere
2020-01-25 05:26
ah!

swaroopshere
2020-01-25 05:33
ok now i dont see the error for requestId anymore, but i see the BodyMismatch error from above logline. My DSL ensures there are 12 elements and the test request also has 12 elements

swaroopshere
2020-01-25 05:33
```21:27:26.988 [Thread-15 ] DEBUG [-,,] [,] DEBUG a.c.d.p.c.m.RequestMatching : Request mismatch: [BodyMismatch(expected={"joinedTimestamp":100,"app":"phone","notificationDelay":10000,"role":"Role","participantDevice":null,"subject":"005xx000001Svyg","highWatermark":null,"persistedId":null,"context":"Context","doNotReceiveOwnMessagesBack":false}, actual={"joinedTimestamp":1579930046352,"app":"phone","leftTimestamp":null,"notificationDelay":10000,"role":"Role","participantDevice":null,"subject":"005xx000001Svyg","highWatermark":null,"context":"Context","persistedId":null,"doNotReceiveOwnMessagesBack":false,"lastActiveTimestamp":null}, mismatch=Expected a Map with 10 elements but received 12 elements, path=$.participants.0, diff={ - "joinedTimestamp": 100, + "joinedTimestamp": 1579930046352, "app": "phone", + "leftTimestamp": null, "notificationDelay": 10000, "highWatermark": null, - "persistedId": null, "context": "Context", - "doNotReceiveOwnMessagesBack": false + "persistedId": null, + "doNotReceiveOwnMessagesBack": false, + "lastActiveTimestamp": null })] :```

swaroopshere
2020-01-25 05:33
does ordering of the elements in the request and the DSL matter?

uglyog
2020-01-25 05:38
No, but `Expected a Map with 10 elements but received 12 elements` means that this must be a consumer test? There are two extra attributes that were not expected.

swaroopshere
2020-01-25 05:42
yeah this is a consumer test

uglyog
2020-01-25 05:43
Then the matching will be strict, and not allow extra attributes

swaroopshere
2020-01-25 05:44
i see. Let me look again at my definition and the actual request that gets generated. Thank you for all your help @uglyog!

kevinkontcheu
2020-01-26 20:29
Please i need help. Can someone help me to write this JSON with PactDslJsonBody? I've tried some things but it's not working

kevinkontcheu
2020-01-26 20:29
{ "comment": { "commentaction": "UPDATE", "content": "content", "locationid": 1234, "locationname": "locationname", "username": "username" }, "geofencePoints": [ { "latitude": 1.0, "longitude": 1.0 }, { "latitude": 2.0, "longitude": 2.0 }, { "latitude": 3.0, "longitude": 3.0 } ] }

abubics
2020-01-27 22:17
it's been about 18 months since I did Android stuff . . . which mockwebserver is that? I'm pretty sure I just used regular Pact libs and Kotlintest with my API client class

abubics
2020-01-27 22:19
oh I see. No, I've never used Pact to spin up a mock server for Android. I just replaced my API client class in `androidTest` with a mock implementation

swaroopshere
2020-01-28 03:08
Ok so i have confirmed that I have defined 12 attributes for the object within an array. The request also has 12 attributes, so the number of attributes should have matched, but for some reason this exception keeps getting thrown. I wonder if this is an issue with RequestMatching? I am posting part of the DSL definition and also the exception log

swaroopshere
2020-01-28 03:08
DSL - ```.array("participants") .object() .numberType("joinedTimestamp",100) .stringType("app","phone") .numberValue("leftTimestamp", null) .numberType("notificationDelay", 10000) .stringValue("highWatermark", null) .stringValue("persistedId", null) .stringType("role", "Role") .stringType("context", "Context") .booleanType("doNotReceiveOwnMessagesBack", false) .stringValue("participantDevice", null) .numberValue("lastActiveTimestamp", null) .valueFromProviderState("subject", USER_ID_EXP,"005xx000001Svyg") .closeObject() .closeArray()```

swaroopshere
2020-01-28 03:09
Debug LogLIne - ```19:03:23.695 [Thread-15 ] DEBUG [-,,] [,] DEBUG a.c.d.p.c.m.RequestMatching : Request mismatch: [BodyMismatch(expected={"joinedTimestamp":100,"app":"phone","notificationDelay":10000,"role":"Role","participantDevice":null,"subject":"005xx000001Svyg","highWatermark":null,"persistedId":null,"context":"Context","doNotReceiveOwnMessagesBack":false}, actual={"joinedTimestamp":1580180603169,"app":"phone","leftTimestamp":null,"notificationDelay":10000,"role":"Role","participantDevice":null,"subject":"005xx000001Svyg","highWatermark":null,"context":"Context","persistedId":null,"doNotReceiveOwnMessagesBack":false,"lastActiveTimestamp":null}, mismatch=Expected a Map with 10 elements but received 12 elements, path=$.participants.0, diff={ - "joinedTimestamp": 100, + "joinedTimestamp": 1580180603169, "app": "phone", + "leftTimestamp": null, "notificationDelay": 10000, "highWatermark": null, - "persistedId": null, "context": "Context", - "doNotReceiveOwnMessagesBack": false + "persistedId": null, + "doNotReceiveOwnMessagesBack": false, + "lastActiveTimestamp": null })] : ```

swaroopshere
2020-01-28 03:16
it seems the the `.numberValue("leftTimestamp", null)` and `.numberValue("lastActiveTimestamp", null)` arent being recognized from DSL

uglyog
2020-01-28 03:23
oh, why you using nulls, should they not have actual numbers in those fields?

uglyog
2020-01-28 03:26
If you're expecting fields with nulls, you should use `nullValue` instead

swaroopshere
2020-01-28 04:15
ah! i see. let me try that out

swaroopshere
2020-01-28 04:32
yes `nullValue` worked. Thank you again!

kbsachin01
2020-01-28 17:05
has joined #pact-jvm

swaroopshere
2020-01-29 01:22
Hello, in my pact contract json file that gets generated after a consumer test passes, I see some issues with character encoding on certain characters. for Eg, a `.` is encoded as ```?``` in some places and as ```?``` in other places. also, `=` shows up as ```\u003d``` . I wonder if I need to specify a certain character set while generating pact file? I am using `pact-jvm-consumer-junit5` , `kotlin-stdlib` in my dependencies, build my app, run my tests via `maven clean package`

uglyog
2020-01-29 01:35
By default Pact-JVM uses UTF-8 for the pact files. Are you using a different character set for your data?

swaroopshere
2020-01-29 01:35
I dont think I am

swaroopshere
2020-01-29 01:36
is there a way to enforce/configure the UTF-8 charset for pactfile generation?

uglyog
2020-01-29 05:25
The default id UTF-8, there is no way to force that. You could try adding the UTF-8 chartype to your content type headers

juanma97perez
2020-02-03 11:30
has joined #pact-jvm

juanma97perez
2020-02-03 11:31
Hello, I have a little dude I want include headers in my request ``` Map<String, String> headers = new HashMap<>(); headers.put("Accept-Language", "es-ES"); return builder.given("get request") .uponReceiving("send get request") .path("/api/v1/locale/supported") .method("GET") .headers(headers) .willRespondWith() .status(200) .body(LambdaDsl.newJsonBody(o -> o .stringType("language", "es") .stringType("country", "ES") ).build()) .toPact(); }``` Without headers work correctly, but with headers, I have the next error: java.lang.AssertionError: Pact Test function failed with an exception, possibly due to Mismatches(mismatches=[PartialMismatch(mismatches=[HeaderMismatch(headerKey=Accept-Language, expected=es-ES, actual=, mismatch=Expected a header 'Accept-Language' but was missing)

juanma97perez
2020-02-03 11:31
I don't understand, because I'm only send headers, not comparing

simone.cusimano92
2020-02-03 11:35
has joined #pact-jvm

jemma.wells
2020-02-03 11:36
has joined #pact-jvm

jemma.wells
2020-02-03 12:49
Hi there. Having a bit of trouble with the matching using the DSL during verification, in particular with an array. The response we want to verify against looks something like this: ```{ "location": { "type": "Category", "categoryId": "12345", "filters": { "colour": [ "blue" ], "size": [ "small" ] } } }``` Within `filters` there could be one or many, and the name of the filter will always vary (though will always contain strings, which is what we want to check). At the moment, i can't seem to find a method that *won't* match on the name of the filter e.g. colour, size etc. I've tried a few things but at the moment i've gotten as far as the below: ```val filteredCategoryLocationJsonBody = PactDslJsonBody() .`object`( "location", PactDslJsonBody() .stringValue("type", "Category") .stringType("categoryId") .`object`( "filters", PactDslJsonBody() .eachLike("filterName", PactDslJsonRootValue.stringType())``` I know that in the above state, it will look for a name of 'filterName' but not sure what else to try/ what's best suited to this. All we really want to know is that anything coming back in the array has type String, or alternatively that if the `filters` object is present, that it isn't empty. Any suggestions? Thanks!

jemma.wells
2020-02-03 13:07
Just to add to this - i also tried using minArrayLike() to see if i could just check that it would at least be present, but it also seems to require a name, and then tries to check against it

matt.fellows
2020-02-03 22:33
Pact will check that the headers you said you wanted in the request were actually present. In your case, you said the ?Accept-Language? header would be sent in the request to `GET /api/v1/locale/supported` but it wasn?t present, so pact failed your test. Update your client code to send the header (if indeed it?s what you want) or remove it from the assertion

uglyog
2020-02-03 22:53
How is it not working? What error are you getting?

uglyog
2020-02-03 22:57
The idea would be to have different tests to check the various combinations that are important. That way each of your tests will define exactly what is expected.

ihor.dobrovolskyi
2020-02-04 11:30
has joined #pact-jvm

sumeshs572
2020-02-04 20:42
What is the actual use case of pact stub service? Can I use it as a request response mapping for api from pact file . I have a pact file in that all the request header and body is recorded how ever in integration tests I am passing different values in the body how can avoid the matching of dynamic values eg a date time stamp from matching for return the response?

asteffey
2020-02-04 20:45
has joined #pact-jvm

konrad.winkler
2020-02-04 21:31
has joined #pact-jvm

uglyog
2020-02-04 21:37
That?s exactly what the stub service was written for. It will match on the path, query parameters and headers, then return the first matching response

asteffey
2020-02-04 21:47
Hi! My team has been using Pact for the past several months and we just recently received approval to make open source contributions back to the project. To get started, I?m currently wrapping up 4 small PRs for pact-jvm. We plan to make some other contributions, especially related to XML, in the future. My team and I are looking forward to participating in the community.


sumeshs572
2020-02-04 22:27
How ever I am having an issue in matching a date time stamp value recorded on pact file , actual request body in integration test have a new value and complaining actual value x and expected y so not returning the response , can use the java refer for the matching rule

uglyog
2020-02-04 23:48
Can you provide the actual logs?

samuel.hodgkinson
2020-02-05 10:16
has joined #pact-jvm

samuel.hodgkinson
2020-02-05 10:18
Seen issues around providers in .Net for example, not supporting v3 matchers, so I was thinking it would be better if PactJVM didn't default to v3 spec (until all implementations support v3 fully) as it can cause issues when providers then come to verify those pacts.

sumeshs572
2020-02-05 15:11
This is the error while matching request

sumeshs572
2020-02-05 17:39
Do you have any reference examples for regex

uglyog
2020-02-05 20:50
That?s a different stub service. What one are you running?

sumeshs572
2020-02-05 20:51
Pact-1.77.0 cli version

uglyog
2020-02-05 20:57
That would be a normal mock server, and will validate the bodies. The one that does not is https://hub.docker.com/r/pactfoundation/pact-stub-server

sumeshs572
2020-02-05 21:00
Pact-stub-service I am using here

uglyog
2020-02-05 21:01
I?m not across what that one does. @bethskurrie will have more info

sumeshs572
2020-02-05 21:02
Thanks

sumeshs572
2020-02-05 21:10
@bethskurrie I am trying to figure out the requests mapping for a date time stamp value and another unique identifier

sumeshs572
2020-02-05 22:36
Do I need to use docker version or cli version 1.77.0 also works with matching rules

bethskurrie
2020-02-05 22:36
the format for v3 is supported, however, the new matching rules introduced in v3 aren't yet.

sumeshs572
2020-02-05 22:40
Regex and date format is supported right?

bethskurrie
2020-02-05 22:40
regex is, date format isn't

sumeshs572
2020-02-05 22:41
Ok

sumeshs572
2020-02-05 22:43
Even though I gave regex .* why it is complaining not matching could you please the above screenshot for matching rules

sumeshs572
2020-02-05 22:44
Review the above matching rules screenshot

bethskurrie
2020-02-05 22:54
I can't see a screenshot @sumeshs572

sumeshs572
2020-02-05 22:56
Are you able to see this

bethskurrie
2020-02-05 23:04
um, that's a really weird error message

bethskurrie
2020-02-05 23:04
it looks like it's doing a diff on the actual pact itself

bethskurrie
2020-02-05 23:04
not your requests.

bethskurrie
2020-02-05 23:05
If you can create a github project to recreate the issue, I'll have a look at it.

alan.nichols
2020-02-06 17:43
Hi all. I'm trying to set up some PACT consumer tests on our android app and ran into issues when trying to use the documented approach of making a retrofit client in a unit test and using that. We attach some headers using a network interceptor and I couldn't attach them in a way that would mirror any future changes to the production app without having to mock out the Context and many other things. I then tried to run the test as an Instrumented Unit Test, where I could get the okHttp client from the app and use that, but I've run into an error: ``` Caused by: java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/message/BasicHeaderValueParser; in class Lorg/apache/http/message/BasicHeaderValueParser; or its superclasses (declaration of 'org.apache.http.message.BasicHeaderValueParser' appears in /system/framework/org.apache.http.legacy.jar)``` The same config was running correctly when the test was a unit test so I'm thinking that there is something about how PACT is running that is conflicting with some http setup on the device? Has anyone else managed to run PACT tests as Instrumented Unit Tests? Any ideas of what to look into next would be greatly appreciated.

uglyog
2020-02-06 22:28
Pact-JVM uses the Apache HTTP client libraries, so the Instrumented Unit Tests must be changing the version of those libraries and causing that issue. I think that Android has it's own version of the Apache HTTP client which is not compatible.

uglyog
2020-02-06 22:30
I disagree with that. Pact-JVM has been V3 compliant for 3 years now. If there is no pain, the other language implementations will have no incentive to move and everyone will be stuck with V2

abubics
2020-02-06 22:37
Can you link the documented example with Retrofit? I'd like to see if it's similar to what I've done before :slightly_smiling_face:

audun.halland
2020-02-06 22:40
@audun.halland has left the channel


alan.nichols
2020-02-07 10:25
Ah that doesn't sound promising then :disappointed: I would have been perfect to use the same networking as the real app.

juanma97perez
2020-02-07 10:48
Hello

juanma97perez
2020-02-07 10:48
I have the next code:

juanma97perez
2020-02-07 10:48
```@RunWith(SpringRunner.class) public class HelloContractTest { @Rule public PactProviderRuleMk2 mockProvider = new PactProviderRuleMk2("poc-two", null, 8089, this); private RestTemplate restTemplate = new RestTemplateBuilder().rootUri("http://localhost:8089").build(); private final String BEARER_TOKEN = "Bearer eyJhbGciOiJSUzI1NiJ9.eyJqdGkiOiJiNzky"; @Pact(consumer = "poc-one") public RequestResponsePact createContractPocOneTest(PactDslWithProvider builder) { Map<String, String> headers = new HashMap<>(); headers.put(HttpHeaders.AUTHORIZATION, BEARER_TOKEN); return builder.given("get request") .uponReceiving("send get request") .path("/api/v1/logger/hello") .method("POST") .headers(headers) .willRespondWith() .status(200) .matchHeader(HttpHeaders.CONTENT_TYPE, "application/json") .body(LambdaDsl.newJsonBody(o -> o .stringType("message", "hello") .stringType("defaultMessage", "hello") ).build()) .toPact(); } @PactVerification(fragment = "createContractPocOneTest") @Test public void givenGetRequestLocalesShouldReturnDefaultLocalesInMockProvider() { final HttpHeaders headers = new HttpHeaders(); headers.set(HttpHeaders.AUTHORIZATION, BEARER_TOKEN); final HttpEntity<String> entity = new HttpEntity<>(headers); ResponseEntity<Map> response = restTemplate.exchange("/api/v1/logger/hello", http://HttpMethod.POST, entity, Map.class); assertEquals(200, response.getStatusCode().value()); } }```

juanma97perez
2020-02-07 10:49
And when I execute this code, I have the next error:

juanma97perez
2020-02-07 10:49
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:8089/api/v1/logger/hello": Connect to localhost:8089 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused); nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8089 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)

juanma97perez
2020-02-07 10:49
I don't know what is, I was 2 or 3 days with this error, help please :disappointed:

juanma97perez
2020-02-07 11:48
UPDATE: I am debugging and mockServer is null in PactProviderRuleMk2

wesleythomaswilliams
2020-02-07 13:46
@juanma97perez Whenever I've seen that kind of error, it's because my service wasn't available on the port specified. If you put a debug point on the line starting with `ResponseEntity<Map>` can you then try and hit your api via postman. If it fails, there's something wrong with your configuration that brings up your service. I'm far from an expert in all this and not sure if we're doing things the best way, but you may find it interesting to see how we do things with junit5 and spring for our contract tests in my team. ```@ActiveProfiles("pact") @ExtendWith(PactConsumerTestExt.class) @PactTestFor(providerName = "consumer_service", port = "1337") @SpringBootTest(classes = { ConsumerRestClient.class, FeignClientConfiguration.class, JacksonConfiguration.class, FeignAutoConfiguration.class }) public class ConsumerServiceConsumerPactTest { private static String inboundConsumerServiceResponse; @Inject private ConsumerRestClient consumerRestClient; @Inject private ObjectMapper objectMapper;``` We then use our bootstrap.yml to define the pact profile (referenced in the @ActiveProfiles annotation): ```spring: profiles: pact consumer: url: localhost:1337``` As we use a FeignClient, that looks like this: ```@FeignClient(name = "consumer", url = "${consumer.url}", configuration = FeignClientConfiguration.class) public interface ConsumerRestClient { @RequestMapping(method = RequestMethod.PUT, value = "/v1/search/find-by-identifier?alias=sku&value={sku}&caller=service_name") ConsumerWrapperDtoV1 getConsumerWrapper(@PathVariable("sku") String sku); }``` At some point I'll put all this on a medium post. Hope some of that was useful.

sam774
2020-02-07 17:47
Has anyone had any thoughts about what a pact workflow, with the broker, looks like for a multi-module maven repository - where both the provider and consumer are modules within that same repo? Curious how this would play out, given a lot of maven commands tend to apply to all modules in a multi-module setup, unless you specify otherwise. And if you do have individual jobs for each module, there's an inherent dependency between jobs. (One answer is don't use multi module maven of course, but let's assume that isn't an option)

uglyog
2020-02-08 00:34
One argument could be that as they are both in the same project, there is less risk of drift between the consumer and provider. So Pact may not be needed in this case.

uglyog
2020-02-08 01:28
The other option is to run the consumer and provider builds separately. I'm pretty sure Maven can do that.

abubics
2020-02-08 05:23
Cool, thanks :slightly_smiling_face:

abubics
2020-02-08 05:26
I use different architecture and tooling, so my retrofit usage is a bit dissimilar (e.g. Kotlin, no repository pattern, no DI library, no Context param for Retrofit, etc)

abubics
2020-02-08 05:27
So I manually instantiate the retrofit client, and haven't had issues with Apache HTTP . . . I can check dependencies on historical projects maybe, and see if there's anything interesting, if you're still stuck

abubics
2020-02-08 05:28
but I use OkHttp, because that's what Retrofit came with, I think? Haven't had issues with interceptors not working, and I add Auth headers (for example) usually

ahmadw
2020-02-10 08:25
has joined #pact-jvm

alan.nichols
2020-02-10 09:58
Thanks for the info. Yeah I can attach interceptors but was looking for a way to not have to maintain these in the test to stop production getting out of sync with the tests.

ihor.dobrovolskyi
2020-02-10 10:47
Hello! Can you help me please! I need to create an array like: ```{ "field1":"test", "field2":"test", "field3":[ "string", "string" ] }``` How can I make this request using pact DSL? Thanks!!!


ihor.dobrovolskyi
2020-02-10 11:36
@wesleythomaswilliams Thanks

wesleythomaswilliams
2020-02-10 14:21
@uglyog If I want to drive my provider test execution with Maven and configure the Maven plugin with my PactBroker info as follows: ```<configuration> <pactBrokerUrl>https://wesley.pact.dius.com.au</pactBrokerUrl> <pactBrokerToken>jhgkdfbsdkjfbsdklbfdns</pactBrokerToken> <pactBrokerAuthenticationScheme>Bearer</pactBrokerAuthenticationScheme> ...``` How do I avoid getting this exception at runtime? `java.lang.UnsupportedOperationException: At least one pact source must be present on the test class` My assumption is that this is being generated because my test class doesn't have a `@PactBroker` or `@PactFolder` tag defined (which was intentional, as the info is defined in the pom)

wesleythomaswilliams
2020-02-10 16:03
Kept chipping away at this and my solution now looks like: ```@PactBroker( host = "${pact.broker.host}", scheme = "https", port = "443", authentication = @PactBrokerAuth(token = "${pact.broker.token}")) public class ProviderPactTest {``` ```<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <systemPropertyVariables> <pact.broker.host>http://wesley.pact.dius.com.au</pact.broker.host> <pact.broker.token>jdsfjkhsdfkjhsdjdj</pact.broker.token> <pact.verifier.publishResults>true</pact.verifier.publishResults> <pact.provider.version>${version.number}</pact.provider.version> <pact.provider.version.trimSnapshot>false</pact.provider.version.trimSnapshot> </systemPropertyVariables> </configuration> </plugin>``` I seem to be able to remove the pact plugin entry from my Pom and everything seems to run fine with system properties defined in the surefire plugin.

uglyog
2020-02-10 22:25
You don't need the Pact Maven plugin if you're just using JUnit tests.

abubics
2020-02-10 23:27
Yeah, sounds like you can't use Apache http in that case :upside_down_face: so either allow the drift, or change http library in all places? I'm not sure

alan.nichols
2020-02-11 14:00
Thanks. I'm experimenting with using the android version in the tests by excluding some modules. Will see how that goes...

ahmadw
2020-02-12 07:06
Hi, ```"body": { "data": "succeeded", "responseStatus": { "description": "succeeded", "status": 1 } }``` How can i put a check on response attributes? for example i want to verify that ?data? is null or string!

iaroslav.liashenko
2020-02-12 10:25
Hi! I have pact tests for spring using: ```@RunWith(SpringRestPactRunner.class) @SpringBootTest``` but while executing mvn clean test, tests are executed(I could see failing requests in log) but results are not affect the test run: ```[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 15.905 s - in TestSuite``` Any Ideas how to solve it?

wesleythomaswilliams
2020-02-12 10:36
Our tests use junit/spring and maven and we use these annotations: @ActiveProfiles("pact") @ExtendWith(PactConsumerTestExt.class) @PactTestFor(providerName = "<service_name>", port = "<port>") @SpringBootTest(classes = { ... })


alan.nichols
2020-02-12 10:52
Instrumented Unit test turned out to be a no go as I ran into an error with a JSON regex somewhere in http code not being parsable. I've moved back to a unit test using roboelectric and I'll see how that goes.

iaroslav.liashenko
2020-02-12 10:54
Ok, finally I tried everything. Issue is somewhere between junit5 and maven-surefire. https://dzone.com/articles/why-your-junit-5-tests-are-not-running-under-maven

iaroslav.liashenko
2020-02-12 10:54
this config works for me: ``` <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.19.1</version> <dependencies> <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-surefire-provider</artifactId> <version>1.1.0</version> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.1.0</version> </dependency> </dependencies> </plugin>```

wesleythomaswilliams
2020-02-12 10:57
I'm wondering if this would need to be addressed with some kind of fudge on the consumer side, so that you create multiple contracts for the consumer, one for each endpoint and name the provider for each contract to include the endpoint name. So they mention /example and /other endpoints. So on the consumer side, have separate tests to create separate contracts that look like: ``` { "provider": { "name": "<provider_name>_other" }, "consumer": { "name": "<consumer_name>" },``` ```{ "provider": { "name": "<provider_name>_example" }, "consumer": { "name": "<consumer_name>" },``` This then allows them to spit the provider tests. Not ideal, but could that work?

ahmadw
2020-02-12 11:31
```@PactBroker(host = "http://mashreq.pact.dius.com.au/", port = "8089", protocol = "https", authentication = @PactBrokerAuth(username = "Read/Write Toke", password = "abcd"))``` I am getting 401 error for this Pactbroker configuration, can anyone help


ahmadw
2020-02-12 11:36
i followed the same syntax

ahmadw
2020-02-12 11:36
scheme is now changed to protocol

matt.fellows
2020-02-12 11:37
mm, it would be nice if you could split the annotations across files at least. But within a consumer is probably hard. Might just be a code organisation thing (i.e. extract data fixtures out of the unit test into another place so it?s not so cluttered)

matt.fellows
2020-02-12 11:38
is it not working?

matt.fellows
2020-02-12 11:39
there should be a `scheme` attribute on the `authentication` property, and the password should be `""`

ahmadw
2020-02-12 11:39
i am using Junit and in @PactBroker annotation instead of scheme (Unable to resolved? it is now protocol.

wesleythomaswilliams
2020-02-12 11:40
This works for us: ```@PactBroker( host = "${pact.broker.host}", scheme = "https", port = "443", authentication = @PactBrokerAuth(token = "${pact.broker.token}"))```

matt.fellows
2020-02-12 11:42
I?ll get those docs checked if they?re out of date. Thanks Wes

ahmadw
2020-02-12 11:43
I am doing the same but scheme is not in scope i think

wesleythomaswilliams
2020-02-12 11:48
What version of pact are you using Ahmad? We're using 4.0.4. Wondering if that might be the issue?

ahmadw
2020-02-12 11:48
3.5.0

ahmadw
2020-02-12 11:56
I just updated to 4.0.5

ahmadw
2020-02-12 11:56
and it worked

ahmadw
2020-02-12 11:56
thanks Wes and Matt

neelofer.tamboli
2020-02-12 16:30
I am using au.com.dius:pact-jvm-provider-spring_2.12 version 3.6.14. I am having trouble getting the right provider version on pactbroker for a verified pact: 1. When `pact.provider.version` property is set, then the pact results are not published. 2. When `pact.provider.tag` property is set, then pact results are published to pactbroker but provider version is always 0.0.0 Am I missing something?

wesleythomaswilliams
2020-02-12 17:03
Are you running with maven? Can you share your pom?

neelofer.tamboli
2020-02-12 17:27
Using gradle: ```plugins { id 'java' id "http://au.com.dius.pact" version "3.6.14" } apply plugin: 'org.springframework.boot' bootRepackage { // spring boot is only used to use the application defined on the service module. onlyIf { false } } bootRun { enabled false } dependencies { testCompile( project('..'), "ma.glasnost.orika:orika-core:${orikaVersion}", "org.springframework.boot:spring-boot-starter-test:${springBootVersion}", "org.jolokia:jolokia-core:1.5.0", "au.com.dius:pact-jvm-consumer-junit_2.12:${pactVersion}", "au.com.dius:pact-jvm-provider-spring_2.12:${pactVersion}", 'oauth.signpost:signpost-commonshttp4:1.2.1.2', 'de.flapdoodle.embed:de.flapdoodle.embed.mongo:2.2.0' ) } test { systemProperty 'pact.rootDir', "$buildDir/pacts" systemProperty 'spring.profiles.active', "local" systemProperty 'spring.config.location', "${rootProject.rootDir}/config/" systemProperty 'pactbroker.host', project.properties['pactbroker.host'] systemProperty 'pactbroker.port', project.properties['pactbroker.port'] systemProperty 'pactbroker.tags', project.properties['pactbroker.tags'] systemProperty 'pactbroker.protocol', project.properties['pactbroker.protocol'] systemProperty 'pact.provider.tag', project.version == "latest" ? scmVersion.version : project.version // Do not add the following as pact is not published, maybe try upgrading pact jvm library // systemProperty 'pact.provider.version', project.version == "latest" ? scmVersion.version : project.version systemProperty 'pact.verifier.publishResults', 'true' doFirst { println("Running contract tests.") } onlyIf { gradle.startParameter.taskNames.contains("contractTest") } } task contractTest() { dependsOn test } def pactVersion = project.version == "latest" ? scmVersion.version : project.version def isPullRequest = { return project.hasProperty('prNumber') && project.properties['prNumber'] != null } def pactTags = isPullRequest() ? [ project.properties['prNumber'], project.properties['pactTag']] : [ project.properties['pactTag'] ] pact { publish { version = pactVersion tags = pactTags pactDirectory = "$rootDir/contract-tests/build/pacts" pactBrokerUrl = project.properties['pactbroker.host'] pactBrokerUsername = project.properties['pactbroker.username'] pactBrokerPassword = project.properties['pactbroker.password'] } } pactPublish.dependsOn contractTest```

neelofer.tamboli
2020-02-12 17:31
My contract test files are: ```@RunWith(SpringRestPactRunner.class) @ContextConfiguration(classes = { ... }) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @PactBroker(tags = "${pactbroker.tags}") @Provider("...") @IgnoreNoPactsToVerify public abstract class ContractTest { ... }``` and ```@Consumer("...") @Category({ ContractTest.class }) public class SampleContractTest extends ContractTest{ ... }```

ileshdarji
2020-02-12 18:11
has joined #pact-jvm

wesleythomaswilliams
2020-02-12 22:16
I'll see if I can work out what's wrong in the AM here (UK). We use Maven, but I remember having the same problem, so I may be able to work it out. In the meantime, maybe @uglyog will have an idea.

jks
2020-02-12 22:23
Hello, I'm in the process of trying to create an enhancement for pact-jvm to allow 'ignore-order' matchers on arrays (XML and JSON). For example: ```"content": { #the expected message "array": [ #don't care about order { "id": "a", #must be a "status": "up" #must be up }, { "id": "b", #must be b "status": "down" #can be up or down } ] } ... "matchingRules": { "$.array": { "matchers": [ { "match": "ignore-order" # means array[0] and array[1] will refer to # elements of expected array, but could match # to any element of expected array } ] }, "$.array[*].id": { #this would look for an id element with a and another with b, in any order in actual "matchers": [ { "match": "equality" } ] }, "$.array[0].status": { #array[0] refers to first index with a in expected "matchers": [ { "match": "equality" } ] }, "$.array[1].status": { #array[1] refers to second index with b in expected "matchers": [ { "match": "regex", "regex": "up|down" } ] } }``` This is an enhancement that I could use in my current work and I've seen this type of request on other Pact forums. I've been successful in adding the 'ignore-order' matcher on the Consumer side (i.e. it gets generated in the pact file). Now I'm looking at the matching aspect in JsonBodyMatcher and XmlBodyMatcher. Is this slack channel the best venue to discuss the effort if I run into implementation questions (I already have one or two)? Or should I open up an issue on the pact-jvm GitHub site? Thanks!

uglyog
2020-02-12 22:26
This is changing the behaviour which needs to be able to be replicated in the other implementations. So a more general channel would probably be better. Maybe in #feature-requests? @bethskurrie, what do you think?

james.elsey
2020-02-12 23:10
has joined #pact-jvm

uglyog
2020-02-13 00:57
`pact.provider.tag` was implemented in version 4.0.1, so you might have to upgrade to a 4.x version

uglyog
2020-02-13 00:57
That looks like a defect with 3.6.14, which I think was fixed in the 4.x branch

neelofer.tamboli
2020-02-13 04:13
Thank you both of you. We will have to upgrade then. I quickly tried upgrading, but noticed there are some failures due to upgrade that we need to fix.

me1015
2020-02-13 17:03
has joined #pact-jvm

pact501
2020-02-14 00:03
has joined #pact-jvm

uglyog
2020-02-14 02:36
You can also raise an issue at https://github.com/pact-foundation/pact-specification to discuss it

ryan.dens
2020-02-14 16:27
:wave: Curious what people?s experiences are with the `PactDslJsonBody()` as a way to match response bodies from the provider in the contract of the consumer. My team and I have used this successfully in several simple cases in a way which results in clear, readable, and maintainable expectations. In general though, my team prefers to use our JSON serializer and the POJO objects we work with to build the expectations of our contract e.g. ```RequestResponsePact sendAppCreateWithSessionId(final PactDslWithProvider builder) { final Gson gson = new Gson(); return builder .uponReceiving("Description") .path("/api/v1.0/create") .body(gson.toJson(new Foo("name", "value")) .method("POST") .body(gson.toJson(new Message("Hello, name!"))) .status(200) .toPact();``` this helps us maintain our contract tests more easily. Recently, I ran into the situation where I have an expected body that is a rather complex JSON object, to the point that I would rather use the typesafety I get with using the objects constructors/builders rather than the artisanal representation with the `PactDslJsonBody`. However, one of the fields in an object several layers of composition deep is a field I would like to match using the `PactDslJsonBody`, because it is a `Set<String>` whose contents are subject to change by the provider and not important for the contract between the consumer and the provdider (an ideal case for `PactDslJsonBody.array().stringType("example").closeArray()`. Is there a way to provide matching expectations without using `PactDslJsonBody`? I would rather not have to build the expectations for this complex java object by hand

wesleythomaswilliams
2020-02-14 16:55
The first tests we wrote we just compared json and didn't use the PactDslJsonBody, but now I'm trying to get to grips with it so we can make use of matching and avoid comparing values. I've found it tricky to get the right syntax though.

ryan.dens
2020-02-14 16:59
Agreed. Really what I would like to be able to do is specify body matchers outside the context of the `PactDslJsonBody` object and not in the context of the `PactDslResponse.body(String)` API

ryan.dens
2020-02-14 17:44
If you look at the generated contract when you use `PactDslJsonBody`, the actual response object looks the same, but there?s a different section which describes the matchers for the body, so I don?t think there?s a reason why these two things couldn?t be defined separately

ryan.dens
2020-02-14 17:45
@uglyog Is the kind of contract specified above something that?s possible today? If not, is it a change you would welcome from the community?

ryan.dens
2020-02-14 18:35
I?m also curious how pact-jvm follow Postel?s laws in this realm, in particular the portion referenced in: https://docs.pact.io/getting_started/matching/gotchas#an-empty-hash-in-the-response-means-allow-any-hash

uglyog
2020-02-16 02:31
Yes, what PactDslJsonBody does is build up a normal JSON body and also keep a map of the matchers in a separate collection. There is no reason why you couldn't do that with a POJO.

ryan.dens
2020-02-16 04:03
Cool, I?ll see what I can do to make marchers and pojos play nice together, thanks!

abubics
2020-02-16 22:27
Back on the original question, I started using the Java 8 DSL (https://github.com/DiUS/pact-jvm/tree/master/consumer/pact-jvm-consumer-java8) a couple of years ago, in Kotlin, and I find it quite nice. Still not as good as a Kotlin-first DSL, but (with some sugar) very readable and moderately terse. Regarding matchers, I was using the Groovy DSL for some years before that, so I'm familiar with all the idioms (and baggage?) that came with that. I think siloing the matchers away from the structure might not help much. But I'd love to see what you come up with :slightly_smiling_face:

antonello
2020-02-16 23:22
We?ve recently discovered an issue where `PactRunner` causes a Spring `ApplicationContext` to be created even if the provider tests are filtered by `@Category`

antonello
2020-02-16 23:23
We think we have a fix for it.

antonello
2020-02-16 23:26
@uglyog We haven?t submitted it yet as the resident experts were discussing it reviewing it internally on Friday


baquinteros
2020-02-17 01:22
has joined #pact-jvm

yau.yik.shiung
2020-02-17 16:05
has joined #pact-jvm

yau.yik.shiung
2020-02-17 16:19
hi there would like to get some insight (right/wrong) on the following initiative that i am going to introduce: ? BDD/Cucumber test is often used in microservice isolation testing with by mocking the dependent services ? I am going to replace the current mock server (wiremock) with pact-jvm-server so that the "assumption" made on the mock request/response can be verified on the provider test ? Any potential downside by doing that ? Is this design violating contract testing ?

antonello
2020-02-17 22:18
@uglyog We didn?t merge this as we wanted to give you a chance to have a look first.

antonello
2020-02-17 22:19
We wouldn?t mind a release soon though. It would speed up our builds a lot :smiley:

sumeshs572
2020-02-18 14:19
I am getting this assertion error while running junit provider test , error related to content length header property already present . Have any one faced this error before , any idea ? I am unable to figure out this issue

uglyog
2020-02-18 22:40
You should never set the content-length header. Make sure it is not set in your pact file.

mail961
2020-02-19 07:46
has joined #pact-jvm

robin.vanwijngaarden_
2020-02-19 12:06
has joined #pact-jvm

carolyn.biggar
2020-02-19 17:54
. *pact.provider.version* value restrictions? We're trying to set the pact provider version using gradle when running provider verification tests, something like ```test { useJUnitPlatform() systemProperty 'pactbroker.auth.username', System.getenv('PACT_BROKER_USERNAME') systemProperty 'pactbroker.auth.password', System.getenv('PACT_BROKER_PASSWORD') systemProperty 'pactbroker.auth.scheme', 'basic' systemProperty 'pact.verifier.publishResults', 'true' systemProperty 'pact.provider.version', 'tomte7st' }``` (we'll be varying the version .. when we get it working) We've found the following values work and the pact is published to our broker: '123' 'tomte7st' 'BC26E131' 'bc26e1' However the following values do *not* work, the pact is *not* published to the broker: 'tomtest' 'TOMTEST' 'MEGATEST' What is going on? Is there some validation that requires the version to contain a number? This is problematic for us as we're planning to use the git short sha and there's no guarantee that i'll contain a number (although it often does). Please help? Here's our dependencies/versions: ```dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" testImplementation "org.junit.jupiter:junit-jupiter-api:5.4.2" testImplementation "org.junit.jupiter:junit-jupiter-params:5.4.2" testImplementation "org.junit.jupiter:junit-jupiter-engine:5.4.2" testImplementation "org.assertj:assertj-core:3.11.1" testImplementation "au.com.dius:pact-jvm-provider-junit5_2.12:3.6.11" }``` Thanks!

carolyn.biggar
2020-02-19 17:54
@thomas.shipley FYI

thomas.shipley
2020-02-19 17:54
has joined #pact-jvm

uglyog
2020-02-19 22:54
When you say the pact is not published, is there any logs or error messages? The version is not used by Pact-JVM, it is just passed on to the broker.

carolyn.biggar
2020-02-19 23:28
Hi @uglyog thanks for looking. We couldn't see any errors :thinking_face: `./gradlew build` completes successfully in both cases; I can't see any logging of the attempt to publish in either case (successful or unsuccessful), even when passing `--info`. Maybe there is somewhere else we should be looking for error logging? Thanks for any help! I know it's tricky to help without seeing the whole thing; at the moment it's part of a work project which I can't share as-is.

uglyog
2020-02-19 23:30
OK, I'm not aware of anything that requires numbers in the version, but I'll ask @bethskurrie.

carolyn.biggar
2020-02-19 23:31
Thank you!

uglyog
2020-02-20 00:10
So it may be because you are using an old version of the Pact Broker. Can you confirm the version you have?

bethskurrie
2020-02-20 00:12
The 400 error response is not being shown when publishing fails in pact JVM.

bethskurrie
2020-02-20 00:13
There's an issue raised for it.

bethskurrie
2020-02-20 00:13
The body will tell you what the validation error is.

bethskurrie
2020-02-20 00:13
I don't know if you're able to turn on verbose logging for the pact broker client at all?

bethskurrie
2020-02-20 00:14
But most likely, it is as Ron says, you have an old version of the broker.

bethskurrie
2020-02-20 00:15
It expected semantic versions, and it's possible that the successful versions were just able to be parsed by the version parsing library that was used

bethskurrie
2020-02-20 00:15
These days, we recommend using the git sha.

bethskurrie
2020-02-20 00:15
If you're on the docker pact broker, the just grab the latest one. It's all backwards compatible.

carolyn.biggar
2020-02-20 00:58
Thanks for the info! We should be able to check out the pact broker version tomorrow (UK time!), will report back when we?ve investigated there!

thomas.shipley
2020-02-20 09:44
Hi @bethskurrie and @uglyog I have just had a look at our broker version which we are running from https://registry.hub.docker.com/r/pactfoundation/pact-broker/tags?page=1 It is set to use latest and is currently running digest: *0eb289f8623b*. Which looks like the latest version of the broker.

thomas.shipley
2020-02-20 09:45
I will do some more investigation to see if I can find the error message in the response body as you suggest.

thomas.shipley
2020-02-20 11:28
I have just attached Charles proxy to the Gradle JVM so I can see the responses coming back from the broker when running the gradle task. This is the response body of a call to ```/verification-results``` ```{ "errors": { "provider_version": ["Version number 'TOMTEST' cannot be parsed to a version number. The expected format (unless this configuration has been overridden) is a semantic version. eg. 1.3.0 or 2.0.4.rc1"] } }``` I am a bit confused now? - reading through this thread it sounds like the broker code was updated in the latest version to not use the semantic approach. Which would suggest an old version of the broker. But as you can see from my last message we are using: `````` As our image.. Any ideas?

matthew.salt
2020-02-20 15:12
has joined #pact-jvm

matthew.salt
2020-02-20 15:13
Hello, I have a question about using pact with junit5. I would like a single consumer test to generate a single .json file with multiple interactions. I want to define the RequestResponsePacts in several ?pact methods? rather than a single chained DSL to male it easier to maintain. Each time I?ve tried though I only get a single interaction in my consumer json file. And tips on how I might be able to achieve this?

wesleythomaswilliams
2020-02-20 15:18
My consumer test: ```@ActiveProfiles("pact") @ExtendWith(PactConsumerTestExt.class) @PactTestFor(providerName = "provider_service", port = "1337") @SpringBootTest(classes = { providerRestClient.class, FeignClientConfiguration.class, JacksonConfiguration.class, FeignAutoConfiguration.class }) public class providerServiceConsumerPactTest { private static final String EAN = "3611441502380"; private static final String INVALID_EAN = "JUNK"; private static String inboundproviderServiceResponse; @Inject private providerRestClient providerRestClient; @Inject private ObjectMapper objectMapper; @BeforeAll static void beforeAll() throws Exception { inboundproviderServiceResponse = StreamUtils.copyToString(new ClassPathResource("/json/pact/provider-service-find-by-identifier-response.json").getInputStream(), Charset.defaultCharset()); } @Pact(provider = "provider_service", consumer = "consumer_service") public RequestResponsePact validEanProvided(PactDslWithProvider builder) throws Exception { return builder .given("a valid ean is provided") .uponReceiving("a request to get a provider") .path("/v1/search/find-by-identifier") .query("alias=ean&value=" + EAN + "&caller=consumer") .method("GET") .willRespondWith() .status(200) .body(inboundproviderServiceResponse) .toPact(); } @Pact(provider = "provider_service", consumer = "consumer_service") public RequestResponsePact eanValueInvalid(PactDslWithProvider builder) { return builder .given("invalid ean in query params") .uponReceiving("a request to get a provider") .path("/v1/search/find-by-identifier") .query("alias=ean&value=" + INVALID_EAN + "&caller=consumer") .method("GET") .willRespondWith() .status(404) .toPact(); } @Test @PactTestFor(pactMethod = "validEanProvided") void testValidEanProvided() throws Exception { // State final InboundproviderWrapperDto expectedInboundproviderWrapperDto = objectMapper.readValue(inboundproviderServiceResponse, InboundproviderWrapperDto.class); // Test InboundproviderWrapperDto inboundproviderWrapperDto = providerRestClient.getproviderWrapper(EAN); // Assert assertEquals(expectedInboundproviderWrapperDto, inboundproviderWrapperDto); } @Test @PactTestFor(pactMethod = "eanValueInvalid") void testInvalidEanProvided() { // Test FeignException feignException = assertThrows(FeignException.class, () -> providerRestClient.getproviderWrapper(INVALID_EAN)); // Assert assertEquals(404, feignException.status()); } }```

wesleythomaswilliams
2020-02-20 15:18
My pact: ```{ "provider": { "name": "provider_service" }, "consumer": { "name": "consumer_service" }, "interactions": [ { "description": "a request to get a provider", "request": { "method": "GET", "path": "/v1/search/find-by-identifier", "query": { "alias": [ "ean" ], "value": [ "3611441502380" ], "caller": [ "consumer" ] } }, "response": { "status": 200, "body": { "provider": "6xkh4x0q", "identifiers": [ { "alias": "ean", "value": [ "3611441502380" ] } ], "aliases": [ "kb0w8tsa" ] } }, "providerStates": [ { "name": "a valid ean is provided" } ] }, { "description": "a request to get a provider", "request": { "method": "GET", "path": "/v1/search/find-by-identifier", "query": { "alias": [ "ean" ], "value": [ "JUNK" ], "caller": [ "consumer" ] } }, "response": { "status": 404 }, "providerStates": [ { "name": "invalid ean in query params" } ] } ], "metadata": { "pactSpecification": { "version": "3.0.0" }, "pact-jvm": { "version": "4.0.4" } } }```

sramakrishnan
2020-02-20 16:16
has joined #pact-jvm

sramakrishnan
2020-02-20 16:16
has joined #pact-jvm

sramakrishnan
2020-02-20 16:16
has joined #pact-jvm

matthew.salt
2020-02-20 17:45
Thanks. All looks good now!

paul.davies
2020-02-21 03:22
Thank you @bethskurrie and @uglyog for your help just now. You were correct. It was due to an older version of the gson open tracing. I?ve bumped that up to the current version and we?ve now got tests getting verified. Your super fast response and turn around are to be envied. Brilliant and thanks again!

alan.nichols
2020-02-21 10:03
Hi everyone. I?ve successfully created a proof of concept test and have a ci job to run them and publish to the broker. The pactPublish gradle task works locally but not on CI. Has anyone run into something similar? Looking for any extra info while I look into networking set up on CI boxes and AWS security groups.

uglyog
2020-02-21 10:18
Are there proxies on the CI server?

carolyn.biggar
2020-02-21 10:20
@bethskurrie is it possible the semantic version validation is still in the current version of the pact broker? If there is some config we can set to override it would you be able to point us in the direction of that? Many thanks!

sumeshs572
2020-02-21 11:34
Is there any way we can over ride some of the provider test matching equality comparison in provider tests

wesleythomaswilliams
2020-02-21 13:19
Hi @sumeshs572 can you give an example?

sumeshs572
2020-02-21 15:07
Are you able to see the screenshot attached

sumeshs572
2020-02-21 15:08
It?s saying no matches defined and using equality

sumeshs572
2020-02-21 15:09
One more question I have is publish the verification results it?s saying pact.verifier.publishresults disabled

sumeshs572
2020-02-21 15:09
How to enable that in the junit provider test or gradle build

wesleythomaswilliams
2020-02-21 15:38
I meant can you give an example, using your code of what you have today and what you're trying to achieve through overriding the matching. In regards to the pact.verifier.publishresults, we use Maven rather than gradle and we had to set a system property variable <pact.verifier.publishResults>true</pact.verifier.publishResults>. That was done inside our surefire plugin definition. I'm not sure if you can do something similar in Gradle?

sumeshs572
2020-02-21 16:03
I could pass as a system property

sumeshs572
2020-02-21 16:04
Next I am seeing this msg skipping publishing verification

wesleythomaswilliams
2020-02-21 16:23
Is a reason for skipping provided? Also, is there anyway you can run slack on your system, so you don't have to photograph the screen?

sumeshs572
2020-02-21 16:52
I don?t see any error as such,pact slack forum as of now blocked in office laptop :thinking_face:

bethskurrie
2020-02-23 23:15
Peeps, the amazing @uglyog has been on a productivity rampage. I'd like to highlight one of my favourite new features, which is that you can now pass in an arbitrary pact URL to be verified. This will support the "pact content changed" webhook workflow, allowing you to use webhook template parameters to pass the pact URL through from the webhook to the verification job, allowing you to get quicker and more accurate feedback on your changed pacts. Thanks Ron! https://github.com/DiUS/pact-jvm/issues/998


uglyog
2020-02-23 23:35
@carolyn.biggar could you get the version of the broker? It would be displayed in the headers that are returned

tjones
2020-02-24 01:13
Party! Thanks @uglyog!!

alan.nichols
2020-02-24 09:16
good idea. I?ll ask the team that configured them and see if there?s anything like that on there.

carolyn.biggar
2020-02-24 12:10
We believe it's the latest (see above) but my colleague @thomas.shipley will capture the response headers to be sure and update , thanks

thomas.shipley
2020-02-24 15:23
Sorry would like to give an update but having some issues getting the broker to start after we switched region on GCP. It seems to be sqllite related but not sure what is going on? as soon as I figure that out I shall update here.

nerea.tamayo
2020-02-24 15:50
Hi guys, when I try to verfy the pact from the provider site, I get this error Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)

nerea.tamayo
2020-02-24 15:52
I?m using ```<groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>4.0.1</version>``` and my broker is provided by PactFlow

nerea.tamayo
2020-02-24 15:52
Do you have any idea about it?

nerea.tamayo
2020-02-24 15:52
Thanks

wesleythomaswilliams
2020-02-24 16:04
@nerea.tamayo Where have you defined your broker information? Url etc?

nerea.tamayo
2020-02-24 16:06
I have in the pom.xml

nerea.tamayo
2020-02-24 16:06
<plugin>                 <groupId>http://au.com.dius</groupId>                 <artifactId>pact-jvm-provider-maven</artifactId>                 <version>4.0.1</version>                                              <configuration>                     <serviceProviders>                         <serviceProvider>                             <name>sb-product</name>                             <pactBroker>                                 <url>https://myurl.pact.dius.com.au</url>                                 <authentication>                                     <scheme>bearer</scheme>                                     <token>tokenXX</token>                                 </authentication>                             </pactBroker>                         </serviceProvider>                     </serviceProviders>                     <pactBrokerUrl/>                 </configuration>             </plugin>

wesleythomaswilliams
2020-02-24 16:07
@nerea.tamayo Ok, I think I know the problem you're facing. Can you show me how your verification test on the provider is accessing the broker details? e.g. In my test, I have: ```@PactBroker( host = "${pact.broker.host}", scheme = "https", port = "443", authentication = @PactBrokerAuth(token = "${pact.broker.token}"))```

nerea.tamayo
2020-02-24 16:13
Sure

nerea.tamayo
2020-02-24 16:13
this is what I have

nerea.tamayo
2020-02-24 16:13
```@RunWith(PactRunner.class) @Provider("sb-product" ) @VerificationReports({"console", "markdown"}) @PactBroker(host = "https://myurl.pact.dius.com.au", scheme = "https", port = "443", authentication = "TokenXX")```

wesleythomaswilliams
2020-02-24 16:21
@nerea.tamayo Ok, so we're doing things a little differently (we are using Maven, Junit5 and Spring) and as you're defining the broker information in both the plugin in the pom and the test, I'm not 100% sure the problem you're having is the same as the one we faced, but we've done this. 1. Completely removed the pact plugin from our pom (but kept the dependency declaration, see below). 2. Configured the broker etc via system property variables in the surefire plugin (see below). 3. Referenced those properties in our test (see previous). Pact dependencies in pom: ```<dependency> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-junit5</artifactId> <version>${pact.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>${pact.version}</version> <scope>test</scope> </dependency>``` Surefire plugin config in pom: ```<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <systemPropertyVariables> <pact.broker.host>http://xxx.pact.dius.com.au</pact.broker.host> <pact.broker.token>fTxxx</pact.broker.token> <pact.verifier.publishResults>true</pact.verifier.publishResults> <pact.provider.version>${pact.provider.version}</pact.provider.version> <pact.provider.version.trimSnapshot>false</pact.provider.version.trimSnapshot> </systemPropertyVariables> </configuration> </plugin>``` We've configured things this way as we found a problem with our tests picking up the correct broker details from the pact plugin definition in our pom. @bethskurrie alluded to a problem in this area, but we never managed to find out exactly what the cause is. However, if we move that config to the surefire plugin, everything worked fine for us. We also don't use PactRunner or the SpringPactRunner, relying on Junit5 and I think the runners were needed for Junit4? @uglyog is that right as I'm really unsure on that?

nerea.tamayo
2020-02-24 16:34
Thnaks a lot, you gave some steps to follow, so in spite of having some differences, I?ll try to adapt your solution to my project

nerea.tamayo
2020-02-24 16:34
thanks a lot!!

wesleythomaswilliams
2020-02-24 16:50
Hope it proves useful.

uglyog
2020-02-24 21:06
One thing to check is that your provider is actually running on port 8080. Is it a spring boot app?

uglyog
2020-02-24 21:07
Correct, the runners are for JUnit 4

bethskurrie
2020-02-25 05:54
@thomas.shipley are you using sqlite for a production pact broker instance?

bethskurrie
2020-02-25 06:15
Ok, @carolyn.biggar I think I've worked it out. I had thought that the `order_versions_by_date=true` configuration skipped the version number validation altogether, but it doesn't. It still checks that the version number fits one of the following formats `"%M.%m.%p%s%d", "%M.%m", "%M"`

bethskurrie
2020-02-25 06:16
This will basically pass if there's a digit anywhere in the version number.

bethskurrie
2020-02-25 06:16
People have been using git shas for years without any issues, and I think nobody has ever had a problem because the chances of a git sha *not* containing a digit are vanishingly small.

bethskurrie
2020-02-25 06:18
I think if you're using real data with real git shas (even short ones), you won't have a problem.

bethskurrie
2020-02-25 06:20
> It is set to use latest

bethskurrie
2020-02-25 06:22
@thomas.shipley we haven't yet introduced any breaking changes to the Pact Broker API, and it should auto upgrade the database without issue, but it's a bit dicey using `latest` nonetheless. I'd suggest to follow best practice, which is to choose a fixed tag for your docker configuration.

bethskurrie
2020-02-25 06:26
I've raised this issue @carolyn.biggar https://github.com/pact-foundation/pact_broker/issues/329 but I don't actually think it's a blocker for you, as I said.

thomas.shipley
2020-02-25 09:31
@bethskurrie - Ah ok - thanks for raising an issue. Agreed it is probably not a blocker and just something I noticed while testing and only using chars in my input strings. Also we are not going to be using sqlite for production - this was part of a investigation piece internally to decide if we should use pact for consumer-driven contract testing. We have decided to continue with it :party_parrot: - so we need to setup a production DB for it and I will be sure to not use the latest tag either - thanks for the tip :slightly_smiling_face:

thomas.shipley
2020-02-25 09:34
Oh and the issue I was seeing yesterday when trying to setup a new broker is nothing to do with Pact. It is something to do with our K8s environment - the sqlite DB didn?t setup correctly when using a mounted volume on the pod but did when using the pods local disk? it used to work in both scenarios :man-shrugging: - but we will be looking at setting up a production DB like postgres so this won?t be an issue.

nerea.tamayo
2020-02-25 09:55
yes, it?s an springboot application

thomas.shipley
2020-02-25 10:11
A colleague of mine did the maths on how likely it is to get a short sha without a digit.. from his message: _short sha?s are by default 7 chars in length, and made up of hex chars, so there?s a 6/16 chance of not getting a number for any 1 digit. thus the probability of not getting a digit in 7 characters is (6/16)^7 = 0.00104, or *0.1%*, or 1 in 1000 times you?ll see no digits in a default short sha_

carolyn.biggar
2020-02-25 17:21
Thank you Beth!

sumeshs572
2020-02-25 20:16
I have a quick question, like pact-stub service is there any alternative for the stub mock ?server because we have some permission issues in running stub cli service etc

sumeshs572
2020-02-25 20:25
Mainly I was looking for a Junit way for mock service

uglyog
2020-02-25 21:00
No, I don?t think there is. What are you trying to do? Would something like wiremock not work for you?

sumeshs572
2020-02-25 22:43
I am getting this error skipping publishing verification results even though I am passing the VM argument any idea why this publishing verification results not happening

uglyog
2020-02-25 22:46
For Gradle, it needs to be `-P` not `-D`

sumeshs572
2020-02-25 22:46
Ok

sumeshs572
2020-02-25 22:50
Tried it no luck

uglyog
2020-02-25 22:52
You have put it in the environement variables. What you should have done is edited the `-D` and changed it to a `-P`

sumeshs572
2020-02-25 22:57
IJ VM Argos and env variable did not worked argument worked now publishing the verification results to broker thanks :blush:

bethskurrie
2020-02-26 00:26
I'll try and get the fix out before you publish 1000 pacts then @thomas.shipley!

paulg4321
2020-02-27 07:22
has joined #pact-jvm

paulg4321
2020-03-02 05:44
Hey Guys, I was trying to implement pact in android following the https://github.com/DiUS/pact-workshop-android. Will anyone be able to tel me what does the the following log indicate . "http://java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:9292"

ankit992
2020-03-02 05:47
are you trying to run pacts as instrumentation tests.

paulg4321
2020-03-02 05:47
Nope. unit tests

paulg4321
2020-03-02 05:48
I am using version as per the sample app ```testImplementation "au.com.dius:pact-jvm-consumer-junit_2.11:3.3.6"```

paulg4321
2020-03-02 05:49
Wondering if this error has any relation with the PactProviderRule i am declaring in the test class..

paulg4321
2020-03-02 05:49
```@JvmField @Rule val mockProvider = PactProviderRule(PROVIDER, "localhost", 9292, this)``` This is how i am declaring the PactProviderRule in the test class

ankit992
2020-03-02 05:50
Can you check if something else is running on port 9292 on your system? Also if your code have a different url then this ? ``` service = new Service(networkModule.getRetrofit(mock(Context.class), "http://localhost:9292").create(Service.Api.class));``` and ``` public PactProviderRule mockProvider = new PactProviderRule("our_provider", "localhost", 9292, this);```

ankit992
2020-03-02 05:50
this should be fine

ankit992
2020-03-02 05:51
can you share on which url your service is sending requests in the http logs, you can also debug and check where the request is going ?

paulg4321
2020-03-02 05:53
INFO: --> GET http://localhost:9292/digital/utils/v1/appconfiguration?appName=sample&platformName=Android&appVersion=1.0.0&platformVersion=6.0&appBuildType=debug&timezone=Australia%2FMelbourne Mar 02, 2020 4:35:57 PM okhttp3.internal.platform.Platform log INFO: X-App-Platform: Android Mar 02, 2020 4:35:57 PM okhttp3.internal.platform.Platform log INFO: X-OS-Version: 7.0 Mar 02, 2020 4:35:57 PM okhttp3.internal.platform.Platform log INFO: X-App-Version: 1.0.0 Mar 02, 2020 4:35:57 PM okhttp3.internal.platform.Platform log INFO: --> END GET Mar 02, 2020 4:35:57 PM okhttp3.internal.platform.Platform log INFO: <-- HTTP FAILED: http://java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:9292 This is the info log i am getting when i run the test.

ankit992
2020-03-02 05:57
I?ll try to run the github sample here to see if i can replicate the issue

paulg4321
2020-03-02 05:58
Thanks Ankit .. I have the github sample as well. It just does run fine for me.

ankit992
2020-03-02 06:02
If that?s the case I can only suggest matching the code, and checking if you have something already on the port 9292 running [in case you was trying out the stub server for pacts too].

antonello
2020-03-02 18:31
@uglyog do you have any ideas on how to address https://github.com/DiUS/pact-jvm/pull/1036#issuecomment-593391506 in a different way?

avinash.eediga533
2020-03-02 23:38
has joined #pact-jvm

avinash.eediga533
2020-03-02 23:40
Hey guys Could any one please help me in setting up pact dir for kotlin based project

avinash.eediga533
2020-03-02 23:40
I?m new yo pact thingy

matt.fellows
2020-03-03 00:18
What have you looked at / tried so far?

avinash.eediga533
2020-03-03 00:20
Figured out thanks @matt.fellows

uglyog
2020-03-03 06:17
I'll have some time to look into this weekend

antonello
2020-03-03 06:58
:+1::skin-tone-2:

wesleythomaswilliams
2020-03-03 12:16
@uglyog for `mvn pact:publish` I see there are options for `-Dpact.consumer.version` and `-Dpact.tag` , which I've made use of when integrating with our pipeline. Additionally, I've also integrated the `can-i-deploy` command with our pipeline and that can take the pact broker url and token etc as options. As a result this means I have my pact broker details in two places, my pom and my stage definition in my pipeline groovy file. Ideally I'd like to avoid that duplication. So are there options for passing those values into pact:publish as I do with version and tag?

oleg.shuliak
2020-03-03 14:52
has joined #pact-jvm

oleg.shuliak
2020-03-03 15:06
Hey all. Sorry in advance for stupid question, but i'm very new to gradle and kotlin and, to be honest, it's complicated for me to understand how to publish pact contract to broker service. I've added to `build.gradle`file this code block ```pact { publish { pactBrokerUrl = 'https://localhost:9292' pactBrokerUsername = 'PACT' pactBrokerPassword = 'PACT' } }``` but I don't understand how to trigger this one from a test in Kotlin. Could you, please, show me at least the direction to search for right answer?

uglyog
2020-03-03 22:48
Could you raise a Github issue for that?

uglyog
2020-03-03 22:49
You don't trigger it from a test. You use the Gradle pactPublish task after all the tests have run. It will then publish any pacts files generated from the tests.

oleg.shuliak
2020-03-04 08:53
thanks a lot

jussi.saurio
2020-03-04 17:16
has joined #pact-jvm

oleg.shuliak
2020-03-05 08:59
good morning. Got stuck with PACT publishing verification step with Kotlin. Problem is that, when i run tests with `gradlew test`, test is passing using `Broker` service, but it doesn't publish verification results to PactBroker. This how i use BrokerService ```@PactBroker(host = "localhost", port = "9292", consumers = ["payrollDatevServiceForBroker"]) @PactBrokerAuth(username = "PACT", password = "PACT")``` And when i'm running `gradlew pactVerify` , test is publishing result, but everything is failing, because it doesn't get 200 status of response. This how my `build.gradle` looks like: ```pact { serviceProviders { payrollAttributeServiceForBroker { hasPactsFromPactBroker('http://localhost:9292', authentication: ['Basic', 'PACT', 'PACT']) } } }``` What am i missing? And is it possible to publish results from test, but not from gradle? Thanks in advance

smilewithvammy
2020-03-05 09:09
has joined #pact-jvm

oleg.shuliak
2020-03-05 10:13
solved. added this block and it works: ```val props = System.getProperties() props["pact.verifier.publishResults"] = "true" System.setProperties(props)```

tainguyen
2020-03-05 11:30
has joined #pact-jvm

tainguyen
2020-03-05 11:30
hello everyone

tainguyen
2020-03-05 11:31
would like to send a POST request, where the request body get value from provider state However I am facing the issue: The request body content is escaped after it is rebuilt by using value injected from provider state https://github.com/DiUS/pact-jvm/issues/1031 Does anyone help me to solve this problem?

tainguyen
2020-03-05 11:31
Thanks so much

oleg.shuliak
2020-03-05 12:48
Hi again. Got a question with BrokerService. When I'm running in locally - test can reach it to get the pact and everything works fine. But when i started to host in k8t cluster - i lost my access to the broker from test with this error -> `main.cdc.http.units.ContractVerificationTest > main.cdc.http.units.ContractVerificationTest > initializationError FAILED` `http://au.com.dius.pact.pactbroker.RequestFailedException: Request to path 'path to pact' failed with response 'HTTP/1.1 308 Permanent Redirect'` And i can access this `<path to pact>` from browser and even from postman without any issues. Any idea how to fix that?

tyler.rasor
2020-03-05 12:57
has joined #pact-jvm

reemadhiman92
2020-03-05 19:37
has joined #pact-jvm

uglyog
2020-03-05 22:31
I'll have some time this weekend to look into it

uglyog
2020-03-05 22:32
It's not following the redirect. Where is it redirecting to? You should just use that URL

tainguyen
2020-03-06 03:00
Thank you :slightly_smiling_face:

sjdl
2020-03-06 12:16
has joined #pact-jvm

sumeshs572
2020-03-06 15:13
Query regarding provider test the equality matching fails because pact response and actual provider response differ in multiple dynamic values in api response how we can override the provider equality matching rules ?

wesleythomaswilliams
2020-03-06 15:26
Hi Sumesh, can you give an example of the dynamic values you're referring to

sumeshs572
2020-03-06 16:08
Eg . Date time stamp dynamic value at the response time

wesleythomaswilliams
2020-03-06 16:22
I've made use of the PactJsonDSL matchers, so I have lines like: ```.datetimeExpression("dateCreated", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")```

sumeshs572
2020-03-06 16:23
Let me try this out and get back

phil.brock
2020-03-06 19:19
has joined #pact-jvm

phil.brock
2020-03-09 12:38
@phil.brock has left the channel

vasilisnx
2020-03-09 14:28
has joined #pact-jvm

antonello
2020-03-09 17:41
:point_up: Good to see it works again, but does it mean that the initialisation is not deferred though?

ahsan_bhai
2020-03-09 19:49
has joined #pact-jvm

ahsan_bhai
2020-03-09 19:49
I am looking for some clarification in regards to the recent fix for this issue: https://github.com/DiUS/pact-jvm/issues/768 I've tried to test with `4.0.7` with `@IgnoreNoPactsToVerify` annotation. I get NullPointerException on `PactVerificationContext`. It looks like `context` variable is still set to null when there are no pacts found in pact broker. ```@IgnoreNoPactsToVerify @ExtendWith(SpringExtension.class) @SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT ) @Provider("invalid-provider") @PactBroker( host = "${pact.broker.host}", port = "${pact.broker.port}", tags = "${pact.consumer.tag}", authentication = @PactBrokerAuth(username = "${pact.broker.username}", password = "${pact.broker.password}") ) public class ProviderTests { @LocalServerPort private int serverPort; @BeforeEach void setupTestTarget(PactVerificationContext context) { System.out.println(context); // this returns null context.setTarget(new HttpTestTarget("localhost", serverPort, "/")); } }``` Does anyone have any idea how to NOT fail pact provider tests in JUnit5 when pacts cannot be found. I assume `IgnoreNoPactsToVerify` is for that purpose. But it just doesn't seem to work as desired with JUnit5.

jagmeet_randhawa
2020-03-09 19:57
has joined #pact-jvm

jagmeet_randhawa
2020-03-09 20:04
@ahsan_bhai I think there is something wrong in your code, did you try restarting the PACT server?

ahsan_bhai
2020-03-09 20:05
I don't think it has anything to do with PactBroker instance. I am getting NPE on this line: `context.setTarget(new HttpTestTarget("localhost", serverPort, "/"));`

uglyog
2020-03-09 20:59
@ahsan_bhai the context will be null if there is no pacts to verify, because there are no pacts hence no context. Just make sure you tests check for null values.

ahsan_bhai
2020-03-09 21:06
@uglyog that's what I figured. and just added null check. It worked like a charm. I appreciate your help. Thank you.

tainguyen
2020-03-10 04:26
Thank you for you update. However, I have been creating pacts using framework JUnit 3.6.11

tainguyen
2020-03-10 04:26
```au.com.dius:pact-jvm-consumer-junit_2.12:3.6.11```

tainguyen
2020-03-10 04:27
If I change to 4.0.7, I will update a lot.

tainguyen
2020-03-10 04:29
And after investigation, I think it also come from Consumer when generate expression


simone.cusimano92
2020-03-10 08:15
Hi everyone, I have implemented 2 Consumer Contract Test in a Java Application like this: ```@Pact(provider = "providerName", consumer = "consumerName") public RequestResponsePact generateContract(PactDslWithProvider builder) { RequestResponsePact responsePact = builder .given("Get a apple that exists") .uponReceiving("Retrieve the apple 123, which exists ") .matchPath(format("/apples/%s", "123")) .method(HttpMethod.GET.name()) .headers(this.getRequestHeaders()) .body("") .willRespondWith() .headers(this.getResponseHeaders()) .status(200) .body(this.getDummyResponseBody()) .given("Delete a apple that exists") .uponReceiving("Delete the apple 1234, which exists ") .matchPath(format("/compositions/%s", "1234")) .method(HttpMethod.DELETE.name()) .headers(this.deleteRequestHeaders()) .willRespondWith() .headers(this.getResponseHeaders()) .status(204) .toPact(); return responsePact; } @Test @PactVerification("providerName") public void test_1() { String responseFromCds = this.service.getAppleById("123"); assertThat(responseFromCds).isNotNull(); } @Test @PactVerification("providerName") public void test_2() { ResponseEntity<String> response = this.service.deleteEntities("1234"); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); }``` Both tests are failing with the following message: `http://au.com.dius.pact.consumer.PactMismatchesException: The following requests were not received:` If I merge the two methods into one, it works: ```@Test @PactVerification("providerName") public void test_1() { String responseFromCds = this.service.getAppleById("123"); assertThat(responseFromCds).isNotNull(); ResponseEntity<String> response = this.service.deleteEntities("1234"); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); }``` As @wesleythomaswilliams and @matt.fellows adviced me, I want each test to fail independently of each other. More like this: ``` @Pact(provider = "provider", consumer = "consumer") public RequestResponsePact validThingProvided(PactDslWithProvider builder) { return builder .given("") .uponReceiving("") .path("") .query("") .method("GET") .willRespondWith() .status(200) .body(response) .toPact(); } @Pact(provider = "provider", consumer = "consumer") public RequestResponsePact thingValueInvalid(PactDslWithProvider builder) { return builder .given("") .uponReceiving("") .path("") .query("") .method("GET") .willRespondWith() .status(404) .toPact(); }``` Then tag your tests with `@PactTestFor(pactMethod = "validThingProvided")` `@PactTestFor(pactMethod = "thingValueInvalid")` Unfortunately, I'm using the following dependencies: ``` testCompile group: 'junit', name: 'junit', version: '4.12' testCompile 'au.com.dius:pact-jvm-provider-junit:4.0.6' testImplementation("au.com.dius:pact-jvm-provider-spring:4.0.6") testImplementation('au.com.dius:pact-jvm-consumer-junit:4.0.6')```

simone.cusimano92
2020-03-10 08:15
and @PactForTest is not present . I think this is a solution valid for JUnit 5. Could you please suggest the right configuration/solution for JUnit 4? :slightly_smiling_face: Thanks in advance!

s1apped
2020-03-10 10:33
Hi. I'm having issue running junit5 tests and latest pact consumer versions (4.0.6+). When running gradle test I'm getting below. It works just fine on 4.0.4 `FAILED org.junit.jupiter.api.extension.ParameterResolutionException at ExecutableInvoker.java:200` Any ideas? Thanks

phil.brock
2020-03-10 14:43
has joined #pact-jvm

jarmy
2020-03-10 16:04
has joined #pact-jvm

uglyog
2020-03-10 20:47
Could you create a issue on the GitHub project with the full stack trace?

uglyog
2020-03-10 22:31
JUnit4 @PactVerification annotation has a fragment attribute that works in the same way as the JUnit5 @PactForTest annotation

tainguyen
2020-03-11 03:54
Hi all

tainguyen
2020-03-11 03:56
Are there the way to define a pact with response body is Array may or may not empty

tainguyen
2020-03-11 03:56
something like: ```[{ "id": "001", "name": "John", "projects": [ { "id": 01, "name": "Project1" }, { "id": 02, "name": "Project2" } ] }, { "id": "002", "name": "Peter", "projects": [] } }]```

tainguyen
2020-03-11 03:59
The project may be empty. If it's not empty, I need to verify the "id", "name" exist

uglyog
2020-03-11 04:03
eachLike will check the items in the list, but not fail if it is empty

tainguyen
2020-03-11 04:06
thanks

tainguyen
2020-03-11 04:06
I will try

tainguyen
2020-03-11 04:42
it works. Thanks @uglyog

adamadiopzongo
2020-03-11 16:20
has joined #pact-jvm

timo
2020-03-12 08:41
has joined #pact-jvm

s1apped
2020-03-12 09:38
Hello. I have noticed below warnings when running consumer tests but everything seems to be working just fine. Am I missing something?

wesleythomaswilliams
2020-03-12 09:42
What does the matching rule look like that is creating the error (if you've identified it)?

s1apped
2020-03-12 10:14
look like all of them. Problem is that they are really straight forward `return builder` `.given("Test Case 1")` `.uponReceiving("GET request to retrieve Car details")` `.matchPath(format(SOME_PATH, "\\d+"))` `.method("GET")` `.willRespondWith()` `.status(200)` `.headers(RESPONSE_HEADERS)` `.body(LambdaDsl.newJsonBody((body) -> {` `body.numberType("id", 85);` `body.stringMatcher("country", [A-Z]{3}, "POL");` `}).build())` `.toPact()`

uglyog
2020-03-12 20:53
What version of pact-jvm are you using?

bethskurrie
2020-03-13 03:37
@bethskurrie has renamed the channel from "pact-jvm" to "pact-jvm-help"

bsigney
2020-03-13 05:11
has joined #pact-jvm

bentstuart
2020-03-13 05:28
has joined #pact-jvm

bentstuart
2020-03-13 05:31
well. I see my github ticket is already here :sweat_smile:

ankit992
2020-03-13 05:33
Not really sure if it will work or not, but can you try chaining closeObject method call after stringType

bentstuart
2020-03-13 05:36
Didn't seem to help. But thanks for trying!

bentstuart
2020-03-13 05:40
https://blog.codecentric.de/en/2019/11/message-pact-contract-testing-in-event-driven-applications/ I'm trying to follow along with this fellas example. He is using Kotlin but should be more or less the same I imagine. I can't really tell if I am doing it right either. As Message is a class of the dius.pact package I presume some auto linking is happening there resulting in a callback (at-least trying to).

uglyog
2020-03-13 05:46
Looks like a defect, good thing you already created an issue for it

bentstuart
2020-03-13 05:57
I just added a little note to it btw. but all good. @uglyog thanks for your response. Could I pick your brain a little? Are my thoughts correct in that the linking works like this. You make a @pact function which defines what you expect to retrieve as the consumer. The @PactVerifyProvider function returns the 'actual data' passed into the the @test and would be the content of the message passed to the @Test callback function?

uglyog
2020-03-13 05:58
Yes, that sounds about right

bentstuart
2020-03-13 05:59
Ok cool and in the @Test you are comparing essentially the data the provider has passed in matches the pact files expectations

s1apped
2020-03-13 08:08
jUnit5 and pact 4.0.4

bradyzp
2020-03-13 21:38
has joined #pact-jvm

guidopio.mariotti10_d
2020-03-14 09:14
Hi, I'm the author of the PR up there :point_up_2:. I find incredibly useful to use the Kotlin DSL for pact, however, I start to think that the naming is not that intuitive. Would you be interested in a different proposal for the DSL? I'll also make sure that the existing one gets deprecated appropriately with support to migrate to the new one

uglyog
2020-03-15 00:50
The current one is for Java 8. For a pure Kotlin one, I would create a new module so that Java users are not affected

guidopio.mariotti10_d
2020-03-15 09:29
You would separate the Kotlin one from the Java one? :thinking_face: I'm not planning of rewrite it entirely, just adjusting the naming of some kotlin methods so that it looks nicer

simone.cusimano92
2020-03-16 18:59
Thanks @uglyog :muscle:

bentstuart
2020-03-17 00:29
Hey. Is there any example of doing type matching against the mock-server response? The example here has value matching https://github.com/DiUS/pact-jvm/blob/master/consumer/pact-jvm-consumer-junit5/src/test/java/au/com/dius/pact/consumer/junit5/ArticlesTest.java

bentstuart
2020-03-17 00:30
I am trying to think how I'd do the type matching against httpResponse.getEntity().getContent()

bentstuart
2020-03-17 00:31
maybe I'd need to convert it to Json and do a type match against each json property. I just don't want to re-invent the wheel if there is something already.

tausif2909
2020-03-17 11:06
has joined #pact-jvm

tausif2909
2020-03-17 11:23
Hello, I am looking for example to update request while running provider verification for below calls `/api/asset/1234` & `/api/assets?assetId=1234` .


tausif2909
2020-03-17 11:24
Somewhere I found the link https://github.com/DiUS/pact-jvm/blob/master/pact-jvm-provider-junit/README.md#modifying-the-requests-before-they-are-sent-version-323245 but content is no more available its throwing 404 NOT FOUND Can someone share the example to handle such cases?

tausif2909
2020-03-17 11:24
I tried to use request filters like below but it worked for updating path, not working for query parameters like `/api/assets?assetId=1234`.

tausif2909
2020-03-17 11:24
```@TargetRequestFilter public void updateRequest(HttpRequest request) throws Exception { HttpGet httpGet = (HttpGet) request; URIBuilder builder = new URIBuilder(httpGet.getURI()); builder.setPath(builder.getPath().replaceAll("/api/assets/20000", "/api/assets/" + mediaAssetId) .replaceAll("/api/assets/21000","/api/assets/" + rootGroupAssetId)); System.out.println("Built request is "+request); }```

tainguyen
2020-03-17 11:28
I am using .pathFromProviderState

tainguyen
2020-03-17 11:29
and queryParameterFromProviderState

tausif2909
2020-03-17 11:32
@tainguyen Could you please share example of that? consumer side & provider side both?

tainguyen
2020-03-17 11:32
public RequestResponsePact createPact(PactDslWithProvider builder) { return builder .given("user exists") .uponReceiving("A request to get user details") .path(/users) .queryParameterFromProviderState(id, "${userId}", "001") .method(HttpMethod.GET.name()) .willRespondWith() .status(HttpStatus.OK.value()) ) .toPact(); }

tainguyen
2020-03-17 11:34
On providerSite you will have: @State("user exists") public Map<String,Object> createUser() throws Exception { // write code to create user HashMap<String, Object> map = new HashMap<>(); map.put("userId", "005"); return map; }

tainguyen
2020-03-17 11:34
```dependencies { compile 'au.com.dius:pact-jvm-consumer-junit_2.12:3.6.11' }```

tausif2909
2020-03-17 11:36
ok, I believe this should be done at consumer side, How do I pass parmeterized request from provider verification ?

tainguyen
2020-03-17 11:37
On providerSite you will have: @State("user exists") public Map<String,Object> createUser() throws Exception { // write code to create user HashMap<String, Object> map = new HashMap<>(); map.put("userId", "005"); return map; }

tausif2909
2020-03-17 11:37
aaah ok, ,let me try that, thanks @tainguyen

tainguyen
2020-03-17 11:37
This will return values to consumer

tainguyen
2020-03-17 11:40
This is example on Git


tainguyen
2020-03-17 12:08
I am finding the way to update request body while running provider verification


tainguyen
2020-03-17 12:12
@uglyog I you have bandwidth, could you take a look at my comment and fix? Thanks

tainguyen
2020-03-17 12:13
Or if you have other solution to update request body while running provider verification, please share with me.

tainguyen
2020-03-17 12:13
My dependencies:

tainguyen
2020-03-17 12:14
```compile 'au.com.dius:pact-jvm-consumer-junit_2.12:3.6.14'```

tainguyen
2020-03-17 12:14
And on provider side: ```compile 'au.com.dius:pact-jvm-provider-junit:4.0.7'```

tausif2909
2020-03-17 13:15
I have updated my my dependencies ```<!-- https://mvnrepository.com/artifact/au.com.dius/pact-jvm-consumer-junit --> <dependency> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-consumer-junit_2.12</artifactId> <version>3.6.11</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/au.com.dius/pact-jvm-provider-maven --> <dependency> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-maven_2.12</artifactId> <version>3.6.11</version> </dependency>``` from `3.5.21` & `3.6.7` respectively, But Now it stopped generating pact files

uglyog
2020-03-17 23:55
That's not how it works. The mock server is the one doing the matching, and if everything matches it generates the response.

uglyog
2020-03-18 00:26
I'll have some time to look into Pact-JVM issues this weekend

tainguyen
2020-03-18 02:24
Thanks in advance

tainguyen
2020-03-18 02:30
I have no ideas, but i am working with gradle project

tainguyen
2020-03-18 02:34
And it's working well

tainguyen
2020-03-18 02:35
```<dependency> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-maven_2.12</artifactId> <version>3.6.11</version> </dependency>``` You don't need to add this to consumer side

tausif2909
2020-03-18 04:53
ok, I just found that pacts gets generated under target folder.. before it was generated under user specified folder..

tausif2909
2020-03-18 05:29
Hello All, After upgrading pact dependency to `3.6.11` , All pacts are now generating by default under `target/pacts` folder instead of specified folders

tausif2909
2020-03-18 05:29
my code to specify pact location is like below

tausif2909
2020-03-18 05:29
```@Before public void setPactDirectory() { System.setProperty(PACT_ROOT_DIRECTORY_KEY, PACT_FASTOBJECTS_PATH); }```

tausif2909
2020-03-18 05:30
and all locations are defined under constant like below

tausif2909
2020-03-18 05:30
```/*** Pact settings ***/ String PACT_ROOT_DIRECTORY_KEY = "pact.rootDir"; String PACT_ENTERPRISE_PATH = "../AcceptanceTests/pacts/flex-enterprise"; String PACT_AUTHORISATION_PATH = "../AcceptanceTests/pacts/flex-authorisation-service"; String PACT_TAG_PATH = "../AcceptanceTests/pacts/flex-tag-service";```

tausif2909
2020-03-18 05:31
when I was on ``3.5.21`` it was working fine..

uglyog
2020-03-18 06:08
How are you running the tests?

tausif2909
2020-03-18 06:42
I am running by mvn command like: `mvn -B -Drevision=3.5.10 verify -P pact-tests -http://Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn`

tausif2909
2020-03-18 06:44
I have added path under my pom.xml file ```<systemPropertyVariables> <pact.rootDir>../AcceptanceTests/pacts/</pact.rootDir> <buildDirectory>${project.build.directory}</buildDirectory> [...] </systemPropertyVariables>``` But now its adding all service pacts in same folder.. my existing implementation was generating pact file on different folder for each service

tausif2909
2020-03-18 07:40
Any idea ?

tausif2909
2020-03-18 08:50
2

alan.nichols
2020-03-18 12:27
HI all, my pact test seems passes every time but only generates the contract file sometimes. Has anyone else experienced this?

s1apped
2020-03-18 14:49
Hi. Is it possible to use MockMVC with junit5 provider?

arho.huttunen
2020-03-18 18:57
has joined #pact-jvm

uglyog
2020-03-18 21:44
That's how it is designed to work, all pacts go to the same directory so they can all be published afterwards

adamadiopzongo
2020-03-18 22:20
Hi @here, is there a way to only publish contract verification results from pact-cli or PactFlow REST API?

uglyog
2020-03-18 22:33
Are asking how to skip the verification results if the pact is not loaded from Pactflow?

adamadiopzongo
2020-03-18 22:36
Hi here is my scenario: 1. Verify contracts from PactFlow from the UT (which generates the verifications results) 2. Use the pact-cli or curl (through rest) to push the verification results to PactFlow. I will need to have this call in my CI pipeline later. So I am looking for ways to do #2 above. Thanks!

uglyog
2020-03-18 22:46
You can, when the pact is fetched from pactflow, there are a list of associated links (it's in HAL format). One of the links is`*pb:publish-verification-results`*. You need to post the verifications results to HREF for that link. It is done for each pact file that is verified.

adamadiopzongo
2020-03-18 22:52
I have been trying that, but kept getting 400 Bad Request: ```> * Connection state changed (MAX_CONCURRENT_STREAMS updated)! * We are completely uploaded and fine < HTTP/2 400 < date: Wed, 18 Mar 2020 22:50:30 GMT < content-type: application/hal+json;charset=utf-8 < content-length: 144 < status: 400 Bad Request < vary: Accept < x-pact-broker-git-sha: d15fc575843d8587ba3f6e69cf153e723c30ac0a < x-request-id: cda19179b4ba5b871855ba0f3d4eea05 < x-saas-broker-git-sha: e1d7aaf2 < x-pact-broker-version: 2.51.0 < x-frame-options: SAMEORIGIN < x-xss-protection: 1; mode=block < x-content-type-options: nosniff < referrer-policy: strict-origin < strict-transport-security: max-age=31536000 ; includeSubDomains < * Connection #0 to host http://azongo.pact.dius.com.au left intact {"error":"Error parsing JSON - 783: unexpected token at 'content-delivery-service/target/pacts/reports/provider-content-delivery-service.json'"}```

adamadiopzongo
2020-03-18 22:53
Maybe there is something wrong with my Content-type?

uglyog
2020-03-18 22:53
> `'content-delivery-service/target/pacts/reports/provider-content-delivery-service.json'`

uglyog
2020-03-18 22:54
That looks like you are sending the file name, not the contents of the file

adamadiopzongo
2020-03-18 22:54
hum, yes indeed. Let me fix that and see?

adamadiopzongo
2020-03-18 23:06
Still 400, but now with the following error: ```{"errors":{"success":["can't be blank"],"provider_version":["can't be blank","Version number '' cannot be parsed to a version number. The expected format (unless this configuration has been overridden) is a semantic version. eg. 1.3.0 or 2.0.4.rc1"]}}%```

tausif2909
2020-03-19 13:26
Hi All, I am trying to use .queryParameterFromProviderState()` But I get below error while running the code.

tausif2909
2020-03-19 13:27
```Default ConstructorUnable to get Response...java.lang.IllegalArgumentException: Illegal character in query at index 42: http://localhost:8112/api/assets?assetId=${assetId}&includeDetails =true&page=0&limit=50 Caused by: http://java.net.URISyntaxException: Illegal character in query at index 42: http://localhost:8112/api/assets?assetId=${assetId}&includeDetails=true&page=0&limit=50 [ERROR] Failures: [ERROR] FastObjectsChildAssetsConsumerTest.doCreateGroupFirstLevelMemberResponse The following requests were not received: method: GET path: /api/assets query: [includeDetails:[true], page:[0], limit:[50]] headers: [:] matchers: MatchingRules(rules={}) generators: Generators(categories={QUERY={assetId=ProviderStateGenerator(expression=${assetId})}}) body: MISSING```

tausif2909
2020-03-19 13:28
& my code is like below:

tausif2909
2020-03-19 13:28
``` @Test @PactVerification(fragment = "createGroupFirstLevelMemberResponse") public void doCreateGroupFirstLevelMemberResponse() { log.debug("port is: {}", provider.getPort()); String params = "?" + "assetId=" + "${assetId}" + "&" + "includeDetails=true" + "&page=0" + "&limit=50"; new CustomClient().getResponse(FAST_OBJECTS_API_PATH + GET_ASSETS+params); } @Pact(provider = FLEX_FASTOBJECTS_SERVICE, consumer = FLEX_PUBLISHINDEXER_SERVICE) public RequestResponsePact createGroupFirstLevelMemberResponse(PactDslWithProvider builder) throws JsonProcessingException { Asset memberAsset = assetCreator.createGroupAsset(FIRST_LEVEL_GROUP_ASSET_CHILD, ACCOUNT_ID, AUTHORISED_USER_ID, "firstLevelGroupAsset"); AssetList assetList = new AssetList(Lists.newArrayList(memberAsset)); return createMediaAssetResponse(builder, assetList, "rootGroupFirstLevelMember"); } private RequestResponsePact createMediaAssetResponse(PactDslWithProvider builder, AssetList assetList, String responseName) throws JsonProcessingException { Map<String, String> headers = Maps.newHashMap(); headers.put("Content-Type", "application/json"); return builder .given("There is a request to get the assets " + responseName) .uponReceiving("Returns the assets " + responseName) .path(GET_ASSETS) .method("GET") .queryParameterFromProviderState("assetId","${assetId}","10000") .query("&includeDetails=true&page=0&limit=50") .willRespondWith() .status(200) .headers(headers) .body(objectMapper.writeValueAsString(assetList)) .toPact(); }```

tausif2909
2020-03-19 13:29
Can you suggest, What is wrong with above code

tausif2909
2020-03-20 04:53
Can any one help on this please ?? :point_up_2:

uglyog
2020-03-20 04:56
You're not passing a value for assetId in your query string


uglyog
2020-03-20 04:58
See, assetId = `${assetId}` which is creating an invalid URL, so your CustomClient is not actually making the request

tausif2909
2020-03-20 06:24
@uglyog Could you please suggest me how do I do that?? Where exactly I need to pass the value for assetId?

uglyog
2020-03-20 06:25
What is the assetId? It is a value to you need to pass to your provider.

tausif2909
2020-03-20 06:53
assetId is `21001` @uglyog

uglyog
2020-03-20 07:02
Then you should use that value

tausif2909
2020-03-20 12:14
```While trying to publish pact I get below error [ERROR] Failed to execute goal au.com.dius:pact-jvm-provider-maven_2.12:3.6.14:publish (default-cli) on project flex-publishindexer: The parameters 'pactBrokerUrl' for goal au.com.dius:p act-jvm-provider-maven_2.12:3.6.14:publish are missing or invalid -> [Help 1]```

tausif2909
2020-03-20 12:14
Error started all of sudden

tausif2909
2020-03-20 12:14
Any idea?

tausif2909
2020-03-20 12:37
Please ignore, I have found the problem :point_up_2:

s1apped
2020-03-20 16:25
Hi. Have you made some change to MockServer? In latest version I can't inject MockServer @BeforeEach annotated method ```@BeforeEach public void setUp(MockServer mockServer) {``` with error ```org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter [http://au.com.dius.pact.consumer.MockServer arg0] ```

uglyog
2020-03-20 22:40
That shouldn?t have changed, but I?ll have a look. What version are you using?

uglyog
2020-03-21 02:36
Do you still have `@ExtendWith(PactConsumerTestExt.class)` on the test class?

uglyog
2020-03-21 02:42
Don't worry, I've reproduced the issue

s1apped
2020-03-21 21:19
Great sorry I didn't respond earlier,

ewa
2020-03-22 11:44
has joined #pact-jvm

tausif2909
2020-03-23 07:14
Thanks alot @uglyog

grzegorzkrol90
2020-03-23 08:31
has joined #pact-jvm

arho.huttunen
2020-03-23 09:21
Has anyone tried to make the consumer side agnostic of the providers behind an API gateway? I was thinking that you could just have one `api-gateway` provider that would then figure out which provider behind the gateway handles which request, and publish pacts that have the correctly mapped providers written into it. I just can?t help thinking that maybe this is overcomplicated, and there could possibly be a simpler way to do it.

tjones
2020-03-23 14:58
> publish pacts that have the correctly mapped providers written into it. I?m not sure what you mean by the bit I?ve quoted, but I?ll have a go at answering. I think the answer depends a bit on whether your conceptual units also map to atomically deployable things (and also on what your API gateway is doing). If you have several related micro-services behind one API gateway, then yes, it _might_ make sense for consumers to think of the whole gateway as the provider of the the API. However, from a practical perspective, it?s best if the pacts are between discrete deployment units. You want to be able to say ?does this version X of my consumer successfully communicate with version Y of the provider??, and to be able to say that, you need the consumer and the provider to be easy to reason about from a deployment and versioning perspective. If your whole API gateway is actually version W, V and U of some microservice A, B and C, then it depends. Can you easily say ?this is version Y of the gateway, which is A, B and C exposed at these different prefixes? (or whatever). Another angle on this - if your API gateway is complex (some do quite a bit of rewriting), then perhaps you have pacts between: your consumer -> API Gateway API Gateway -> microservice A API Gateway -> microservice B ?. etc

tjones
2020-03-23 14:59
(also, this is a good question that might benefit from being in #general)

aliihlail
2020-03-23 15:41
has joined #pact-jvm

aliihlail
2020-03-24 05:59
Hi every one. im trying to run contract test using pactFLow. I wrote a simple contract and i tested it using local dockerbroker it is worked correctly. but when i upload the contract the pactFlow i got always the same error as attached in the file

abubics
2020-03-24 06:01
> There were 1 pact failures To me, this says you need to check the pact logs to see what the failure was :slightly_smiling_face:

aliihlail
2020-03-24 06:03
I used the same Pact file and it worked on the local pactbroker

uglyog
2020-03-24 06:03
The log entries before that will display what failed

aliihlail
2020-03-24 06:03
even if the contract file is empty i got the same error

aliihlail
2020-03-24 09:06
Now when im using the verication test i got this error message java.lang.UnsupportedOperationException: At least one pact source must be present on the test class

aliihlail
2020-03-24 09:13
@uglyog can you assist

waquino
2020-03-24 12:47
has joined #pact-jvm

arho.huttunen
2020-03-24 18:07
That?s a good point, maybe I?ll rephrase and ask in #general

josue.boix
2020-03-24 19:12
has joined #pact-jvm

josue.boix
2020-03-24 19:12
Hello everyone!

josue.boix
2020-03-24 19:20
I have an issue when running a MockMvc test with `RestPactRunner` . Can anybody help?

uglyog
2020-03-24 22:07
It would be more helpful to let us know what the issue is before we can answer that question :smile:

uglyog
2020-03-24 22:08
Still, the error would have been displayed in the console

uglyog
2020-03-24 22:09
You haven't provided a source for pact files (i.e. using the @PactFolder or @PactBroker annotations)

tainguyen
2020-03-25 02:57
@uglyog I have a comments on ticket https://github.com/DiUS/pact-jvm/issues/1031 about using generator to replace the fields that correspond to value that need to change when running pact verification. If you have time, pls help me address. Thanks so much

borsuk.artem034
2020-03-25 06:36
Hello, did not get how I can specify lambdaPactDsl for array of the typical objects? ```[{ "type": "type", "title": "title" }, { "type": "type", "title": "title" }, //many the same objects ]```

borsuk.artem034
2020-03-25 08:35
stuck here ```LambdaDslJsonArray body = newJsonArray((rootArray) -> rootArray.object((filter -> { filter.stringMatcher("type", "[\\w\\W]*", "type") .stringMatcher("title", "[\\w\\W]*", "title"); }) ) );```

josue.boix
2020-03-25 09:00
I?ll post the issue below

josue.boix
2020-03-25 09:03
Hello! I have an issue when creating a MockMVC test from the provider side. So I have the following contract test written from the consumer: ```Upon receiving get whatever from service, with { "method": "GET", "path": "/v1/endpoint", "headers": { "Accept": "application/json", "Content-Type": "application/json" } } Service will respond with: { "status": 200, "headers": { "Content-Type": "application/json" }, "body": { "array": [ ] }``` If I verify the contract using `mvn pact:verify` using one of the services deployed in my environment, it works fine, as follows: ```Verifying a pact between consumer and provider [from Pact Broker https://pact-broker] Get returns a response which has status code 200 (OK) includes headers "Content-Type" with value "application/json" (OK) has a matching body (OK)``` But then I write a MockMVC test to verify it from the provider, which looks very similar to this one here: https://github.com/DiUS/pact-jvm/tree/master/provider/pact-jvm-provider-spring The verfication fails, as you can see below: ```Verifying a pact between myConsumer and myProvider Get Whatever MockHttpServletRequest: HTTP Method = GET Request URI = /v1/endpoint Parameters = {} Headers = {Accept=[application/json], Content-Type=[application/json]} Body = <no character encoding set> Session Attrs = {} Handler: Type = com...controller...TypeController Method = public ...myDTO myController.get(java.lang.String) Async: Async started = false Async result = null Resolved Exception: Type = null ModelAndView: View name = null View = null Model = null FlashMap: Attributes = null MockHttpServletResponse: Status = 200 Error message = null Headers = {Content-Type=[application/json;charset=UTF-8]} Content type = application/json;charset=UTF-8 Body = {"myArray":[]} Forwarded URL = null Redirected URL = null Cookies = [] returns a response which has status code 200 (OK) includes headers "Content-Type" with value "application/json" (FAILED) has a matching body (OK) Failures: 0) Get Whatever returns a response which includes headers "Content-Type" with value "[application/json]" Expected 'application/json;charset=UTF-8' to match 'application/json' java.lang.AssertionError: 0 - Expected 'application/json;charset=UTF-8' to match 'application/json'```

tainguyen
2020-03-25 09:05
try ```new PactDslJsonArray() .arrayMinLike(2) .stringType("type","type") .stringType("title","title") .closeObject()```

josue.boix
2020-03-25 09:08
Any clues? I?m running out of ideas here

tainguyen
2020-03-25 09:51
Hello, Does anyone know how to define pact using ```valueFromProviderState``` to verify value in numberType?

tainguyen
2020-03-25 09:53
I define ```.valueFromProviderState("id","${id}",100)``` So, it is understanding id must be string

tainguyen
2020-03-25 09:54
While I expect id is an integer

tainguyen
2020-03-25 09:55
The method ```valueFromProviderState```

tainguyen
2020-03-25 10:00
Do you all have any ideas? Thanks

borsuk.artem034
2020-03-25 11:42
Thanks! Good for me

carolyn.biggar
2020-03-25 19:45
*Incorrect "validated" state on broker for provider test with runtime error* Following on from https://pact-foundation.slack.com/archives/C9VPNUJR2/p1584863869106000?thread_ts=1584800617.098000&cid=C9VPNUJR2 ... When the provider verification test fails due to a *runtime error* - most commonly we have `MissingStateChangeMethod` due to getting the state match up wrong - the results still get published to the broker and *incorrectly show as verified*. This is pretty misleading, because actually the verification test didn't run so we don't know if it would have passed or not - we've had cases where it wouldn't. Could you help me problem solve this? Is it a bug or is there a setting I can tweak so that this shows as "not run" or something else on the broker? Our main requirement is that it doesn't show as "passed" Here's an example using the public broker as suggested - nb the consumer and provider tests are both in the same project for convenience here! https://github.com/csbiggar/pact-example/blob/master/README.md I've added steps to recreate to the readme, let me know if anything is unclear. Many thanks for any help

ravi.dasari
2020-03-25 21:26
has joined #pact-jvm

ravi.dasari
2020-03-25 21:29
@here how do I use pending pacts ? any guides or documentation related to this? I just couldn't find anything except this blog - http://blog.pact.io/2020/02/24/how-we-have-fixed-the-biggest-problem-with-the-pact-workflow/

uglyog
2020-03-25 22:16
Can you raise an issue for that at the Github project?

uglyog
2020-03-25 22:16
A fix would be to change the content type to `application/json;charset=UTF-8`

abubics
2020-03-25 22:17
Did that matcher not get relaxed?

uglyog
2020-03-25 22:18
The values injected from the provider states are parsed as an expression, which will always be a string. Please raise an issue for this at the Github project.

uglyog
2020-03-25 22:19
Please raise a Github issue for this

uglyog
2020-03-25 22:20
Pending pact support is still being worked on. The latest version of Pact-JVM uses the new endpoint, but still verifies all the pacts regarding of status.

uglyog
2020-03-25 22:22
It should have been, but maybe the MockMVC version is doing something different

carolyn.biggar
2020-03-25 23:27
Thanks have done so now, here https://github.com/DiUS/pact-jvm/issues/1058

carolyn.biggar
2020-03-25 23:27
cheers!


ravi.dasari
2020-03-26 02:34
ah. I see . Thanks for the reply

josue.boix
2020-03-26 09:10
I fixed it by changing the content type as you suggested. Thanks @uglyog!

ahsan_bhai
2020-03-26 20:07
Getting 400 error after moving to a different pact broker that has `https` enabled. The tests work fine with current pact broker with `http`

ahsan_bhai
2020-03-26 20:07
``` 14:57:25.693 [Test worker] DEBUG http://au.com.dius.pact.provider.junit.loader.PactBrokerLoader - Loading pacts from pact broker for provider my_provider and tag prod 14:57:25.699 [Test worker] DEBUG http://au.com.dius.pact.provider.junit.loader.PactBrokerLoader - Authentication: Basic 14:57:25.717 [Test worker] DEBUG http://au.com.dius.pact.core.pactbroker.HalClient - Fetching: / 14:57:26.227 [Test worker] DEBUG org.apache.http.client.protocol.RequestAddCookies - CookieSpec selected: default 14:57:26.265 [Test worker] DEBUG org.apache.http.client.protocol.RequestAuthCache - Auth cache not set in the context 14:57:26.267 [Test worker] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection request: [route: {}->http://my_pact_broker:443][total kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 10] 14:57:26.313 [Test worker] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {}->http://my_pact_broker:443][total kept alive: 0; route allocated: 1 of 5; total allocated: 1 of 10] 14:57:26.316 [Test worker] DEBUG org.apache.http.impl.execchain.MainClientExec - Opening connection {}->http://my_pact_broker:443 14:57:26.350 [Test worker] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connecting to my_pact_broker/10.129.3.59:443 14:57:26.528 [Test worker] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connection established 10.207.25.100:51194<->10.129.3.59:443 14:57:26.529 [Test worker] DEBUG org.apache.http.impl.execchain.MainClientExec - Executing request GET / HTTP/1.1 14:57:26.529 [Test worker] DEBUG org.apache.http.impl.execchain.MainClientExec - Target auth state: UNCHALLENGED 14:57:26.530 [Test worker] DEBUG org.apache.http.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED 14:57:26.536 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> GET / HTTP/1.1 14:57:26.536 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Type: application/json 14:57:26.536 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept: application/hal+json, application/json 14:57:26.536 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: my_pact_broker:443 14:57:26.536 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: Keep-Alive 14:57:26.537 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.10 (Java/11.0.2) 14:57:26.537 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate 14:57:26.537 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "GET / HTTP/1.1[\r][\n]" 14:57:26.537 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Type: application/json[\r][\n]" 14:57:26.538 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept: application/hal+json, application/json[\r][\n]" 14:57:26.538 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: my_pact_broker:443[\r][\n]" 14:57:26.538 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]" 14:57:26.538 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.10 (Java/11.0.2)[\r][\n]" 14:57:26.538 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]" 14:57:26.538 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]" 14:57:27.254 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 400 Bad Request[\r][\n]" 14:57:27.254 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "Server: awselb/2.0[\r][\n]" 14:57:27.254 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "Date: Thu, 26 Mar 2020 19:57:26 GMT[\r][\n]" 14:57:27.254 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Type: text/html[\r][\n]" 14:57:27.254 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Length: 236[\r][\n]" 14:57:27.255 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "Connection: close[\r][\n]" 14:57:27.255 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]" 14:57:27.255 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "<html>[\r][\n]" 14:57:27.255 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>[\r][\n]" 14:57:27.255 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "<body bgcolor="white">[\r][\n]" 14:57:27.255 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "<center><h1>400 Bad Request</h1></center>[\r][\n]" 14:57:27.256 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "<center>The plain HTTP request was sent to HTTPS port</center>[\r][\n]" 14:57:27.256 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "</body>[\r][\n]" 14:57:27.256 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "</html>[\r][\n]" 14:57:27.260 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 400 Bad Request 14:57:27.260 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 << Server: awselb/2.0 14:57:27.260 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 << Date: Thu, 26 Mar 2020 19:57:26 GMT 14:57:27.261 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Type: text/html 14:57:27.261 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Length: 236 14:57:27.261 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 << Connection: close Gradle Test Executor 12 finished executing tests. > Task :test FAILED com.trendmicro.np.ms.aggregator.contracttests.UiApiAggregatorProviderTests > com.trendmicro.np.ms.aggregator.contracttests.UiApiAggregatorProviderTests > initializationError FAILED http://au.com.dius.pact.core.pactbroker.RequestFailedException: Request to path '/' failed with response 'HTTP/1.1 400 Bad Request'```

ahsan_bhai
2020-03-26 20:08
This is the message body with `400` ```The plain HTTP request was sent to HTTPS port``` any ideas if I need to do anything different with a pact broker that has `https` enabled?

ahsan_bhai
2020-03-26 21:34
Fixed it! need to have `scheme` set!

tainguyen
2020-03-27 12:22
@uglyog Sorry to bother you. But could you please help me to take a look at my comment on https://github.com/DiUS/pact-jvm/issues/1031

tainguyen
2020-03-27 12:23
I don't know how to use generator to replace the fields in the Request Body that correspond to value that need to change Thanks so much

ina.lopez
2020-03-30 21:29
has joined #pact-jvm

aliihlail
2020-03-31 20:31
``` import http://au.com.dius.pact.consumer.MockServer; import http://au.com.dius.pact.consumer.junit5.PactConsumerTestExt; import http://au.com.dius.pact.consumer.junit5.PactTestFor; import http://au.com.dius.pact.consumer.junit5.ProviderType; import http://au.com.dius.pact.core.model.annotations.Pact; import http://au.com.dius.pact.core.model.messaging.MessagePact; import org.apache.http.HttpHeaders; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.hateoas.MediaTypes; import java.util.HashMap; import java.util.Map; import static io.pactfoundation.consumer.dsl.LambdaDsl.newJsonBody; @ExtendWith(PactConsumerTestExt.class) @PactTestFor(providerName = "contract-service", providerType = ProviderType.ASYNCH) public class PactContractTesting { private static final String CONTENT_HEADER = HttpHeaders.CONTENT_TYPE; @Pact(consumer = "document-service") public MessagePact contractDelegateTest(MessagePact builder) { Map<String, String> metadata = new HashMap<>(); metadata.put(CONTENT_HEADER, MediaTypes.HAL_JSON_UTF8_VALUE); return builder.given("SomeProviderState2") .expectsToReceive("a test message") .withMetadata(metadata) .body(newJsonBody((contract) -> { contract.id("id"); contract.object("currentEmail", (email) -> { email.stringValue("email", ""); }); contract.object("person", (firstName) -> { firstName.stringValue("firstName", "Max"); }); }).getPactDslObject()) .toPact(); } @Test @PactTestFor(pactMethod = "user") public void testContract(MockServer mockServer) { } }```

aliihlail
2020-03-31 20:32
Im writing this code to test an assyncroyns message but i got an eror that i cant use builder.given

uglyog
2020-04-01 04:26
What error did you get?

lbraymusso
2020-04-02 05:40
has joined #pact-jvm

aliihlail
2020-04-02 11:22
`@ExtendWith(SpringExtension.class)` `@ActiveProfiles("test")` `@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)` `@Provider("contact-service")` `@PactBroker()@IgnoreNoPactsToVerify` `public class DocumentVerificationTest {` `@TestTemplate` `@ExtendWith({PactVerificationInvocationContextProvider.class})` `public void pactVerificationTestTemplate(PactVerificationContext context) {` `context.verifyInteraction();` `}` `@State("test case")` `public void test() {` `}` `}`

aliihlail
2020-04-02 11:23
im trying on the provider side to to test the contract. the contract is an amqp. im getting the following error java.lang.UnsupportedOperationException: Only request/response interactions can be used with an HTTP test target

borsuk.artem034
2020-04-02 12:11
```@BeforeEach void setupTestTarget(PactVerificationContext context) { context.setTarget(new AmpqTestTarget(Collections.singletonList("com.yourcompany.main"))); }```

aliihlail
2020-04-02 21:28
@borsuk.artem034 thanks for your answer it is really help but now i have a second issue that i have provider service has to two contracts one rest and amqp when i run the service it run error on the other contract. my question how to configure the class to run only this contract with ignoring the second one.

uglyog
2020-04-02 22:27
With JUnit 5 you can't filter the pacts at the moment. Please raise an issue for that at the github project. THe only way you could really do it is have a different consumer name for the HTTP and async interactions. For example, `contact-service` and `contact-service-async`

aliihlail
2020-04-02 22:31
Thanks for your help for that. i will check it keep you updated

aliihlail
2020-04-02 22:48
@uglyog you meen differn provider name because the consumers are different. and do in need to to only mentioned that in provide annotaion ```@Provider("contact-service-async") @Provider("contact-service")``` or also i need to chang in the pom file

uglyog
2020-04-02 22:49
If the consumers are different, you can have different tests for each consumer. Use the `@Consumer` annotation

aliihlail
2020-04-02 22:52
yes the provider has 2 contracts one HTTP with X consumer and async with Y consumer

aliihlail
2020-04-02 22:56
thanks @uglyog worked

antonello
2020-04-03 06:29
when running provider verification tests, I get this message: [DefaultTestResultAccumulator] Not all of the 28 were verified. Is there any convenient way to figure out which exact state was not verified? I am very reluctant to check 28 states one-by-one by hand. :blush:

uglyog
2020-04-03 06:35
ah, yeah, that is not that helpful. I'll update it to print out the missing ones

antonello
2020-04-03 06:48
Sounds good to me @uglyog - thank you! :)

aliihlail
2020-04-03 09:03
when we upload the pact contract to Pact Flow using mvn pact:publish. I recognize the old contract is still exist. How to replace the new you contract with the old one with doing it manually by deleting the contract integration integration.

borsuk.artem034
2020-04-03 13:14
do "mvn clean" before new run? or always use "mvn clean test"

reemadhiman92
2020-04-03 15:15
hello, How can i verify pact at provider end with mvn command ? is it possible to run via command as , it will not run by mvn clean test .

lbraymusso
2020-04-03 15:55
you can use a `mvn pact:verify` task


ryanlevell
2020-04-03 16:27
has joined #pact-jvm

aliihlail
2020-04-04 21:20
when we upload the pact contract to Pact Flow using mvn pact:publish. I recognize the old contract is still exist. How to replace the new you contract with the old one with doing it manually by deleting the contract integration integration.

uglyog
2020-04-05 04:11
I'm not sure what the question is. Are you asking how to update a contract without deleting the old one?

aliihlail
2020-04-05 13:56
No with deleting the old one

uglyog
2020-04-05 23:17
Versioning in the Pact Broker is documented here: https://docs.pact.io/getting_started/versioning_in_the_pact_broker

martin.nilsson
2020-04-06 13:10
has joined #pact-jvm

paras.vora1801
2020-04-07 02:59
has joined #pact-jvm

paras.vora1801
2020-04-07 14:43
I have a SprintBootApplication & the provider test written is something like: ```package com.inq.auth.contract.test; import http://au.com.dius.pact.provider.junit.Provider; import http://au.com.dius.pact.provider.junit.State; import http://au.com.dius.pact.provider.junit.loader.PactFolder; import au.com.dius.pact.provider.junit.target.Target; import au.com.dius.pact.provider.junit.target.TestTarget; import http://au.com.dius.pact.provider.spring.SpringRestPactRunner; import au.com.dius.pact.provider.spring.target.SpringBootHttpTarget; import org.junit.Before; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; @RunWith(SpringRestPactRunner.class) @Provider("auth_server") @PactFolder("/Users/paras.vora/n_workspace/rt/customer-eapi/target/pacts") @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class ProviderTests { @Before public void setup() { } @State("A request to fetch the authorization token") public void getAuthToken() { } @TestTarget public final Target target = new SpringBootHttpTarget(); }``` For initiating the application, there are some arguments that needs to be passed, like this: title AUTH ``` java -Xdebug -agentlib:jdwp=transport=dt_socket,address=8888,server=y,suspend=n -DuseSSL=false -Dmonitoring.enabled=false -Dmanagement.security.enabled=false -Dlogs.dir=logs -Djmx.host=http://auth.something.com -Djmx.port=9090 -Dserver.address=http://auth.something.com -Dserver.port=10080 -DDB_USER=v2arch -DDB_PASS=munbah1 -jar .\target\some-server-4.0-SNAPSHOT.jar```

paras.vora1801
2020-04-07 14:44
The *@TestTarget* fails to provide these arguments hence, my application fails to initiate.

paras.vora1801
2020-04-07 14:45
Can anyone help how can I provide these arguments while initiating the application with @TestTarget?

uglyog
2020-04-07 23:07
@TestTarget doesn't start your application, spring boot does that. The spring test support will start your test application context before the pact test. You need to have any parameters required by your application provided from the spring context or maybe a before method.

vasilisnx
2020-04-08 10:25
Hi everyone, I started using pact-jvm-consumer-junit a couple of days ago and by looking at the documentation i cannot find if its possible and if yes how would someone create 2 separate fragments for different outcomes of the same interaction with the same provider. So for example see this consumer code ```@Pact(provider = "providerA", consumer = "consumer") public RequestResponsePact fragment1(final PactDslWithProviderBuilder builder) { return builder .given("book doesn't exist") .when("request to create book") .path("/books") .method("POST") .headers(headers) .body(body) .willRespondWith() .headers(responseHeaders) .body(responseBody) .status(200) .toPact(); } @Pact(provider = "providerA", consumer = "consumer") public RequestResponsePact fragment2(final PactDslWithProviderBuilder builder) { return builder .given("book does exist") .when("request to create book") .path("/books") .method("POST") .headers(headers) .body(body) .willRespondWith() .headers(responseHeaders) .body(errorBody) .status(409) .toPact(); } @Test @PactVerification(value = "providerA", fragment = "fragment1") public RequestResponsePact successfulCreation(final PactDslWithProvider builder) { // a test for the first fragment1 success } @Test @PactVerification(value = "providerA", fragment = "fragment2") public RequestResponsePact failCreation(final PactDslWithProvider builder) { // a test for the first fragment2 failure }``` The above example fails. Is that possible? Or whats the right approach if not?

uglyog
2020-04-08 23:16
Looks fine to me. What is the error you are getting?

vasilisnx
2020-04-09 07:57
The error i am getting is ```Test function failed with an exception, possibly due to ExpectedButNotReceived(expectedRequests=[ method: POST path: /books``` So it looks like there is some sort of conflict when running both test cases at the same time, cause when i run individually they both pass. When i run them in one go only one succeeds. The other one fails with the above message. *Edit*: i managed to bypass this issue by adding a delay between tests ``` @Before public void addDelay() throws InterruptedException { Thread.sleep(2500); }``` but i don't think thats a good solution. Any suggestions?

uglyog
2020-04-09 22:57
Your http client library is caching the connections. The sleep works because after that amount of time the http connection would be considered stale.


kjtester
2020-04-10 09:30
has joined #pact-jvm

l.dziedziul
2020-04-10 14:09
has joined #pact-jvm

l.dziedziul
2020-04-10 14:19
Hi all! I've got a question regarding provider tests with junit5 and spring. Is it possible to use `MockMvcTarget` or `WebMvcTest` to avoid spinning up the whole application context? I can't find any example.

tyler.rasor
2020-04-10 14:40
we?re successfully using `MockMvcTarget`, not sure what example we followed

l.dziedziul
2020-04-10 14:41
with junit5? I?ve found only examples for junit4

tyler.rasor
2020-04-10 14:46
ahh, sorry, just checked and we are using 4

l.dziedziul
2020-04-10 14:46
no problem

uglyog
2020-04-11 02:00
MockMvcTarget has not been ported to JUnit 5 yet. Please raise an issue on the Github project for that.


l.dziedziul
2020-04-13 14:24
Hi, I?ve added a PR to fix this issue: https://github.com/DiUS/pact-jvm/pull/1068. I closed the first PR (1067) because I?ve used the wrong GH account :wink:

komeershettyvinod
2020-04-14 17:13
has joined #pact-jvm

aliihlail
2020-04-15 08:50
``` [ERROR] Failed to execute goal au.com.dius:pact-jvm-provider-maven:4.0.8:verify (default-cli) on project contact-service: A type incompatibility occurred while executing au.com.dius:pact-jvm-provider-maven:4.0.8:verify: class http://au.com.dius.pact.core.model.messaging.Message cannot be cast to class http://au.com.dius.pact.core.model.RequestResponseInteraction (http://au.com.dius.pact.core.model.messaging.Message and http://au.com.dius.pact.core.model.RequestResponseInteraction are in unnamed module of loader org.codehaus.plexus.classworlds.realm.ClassRealm @7fad214a)``` My code at the consumer side is working perfectly but when im trying to use mvn pact:verify i got the above error

wesleythomaswilliams
2020-04-15 16:07
@uglyog Something I noticed recently that I wanted to query you about. I have a provider that is consumed from by six other services and results in a total of 17 provider tests. When I run those tests, I get output that looks similar to this for each of the 17 tests: Verifying a pact between myconsumer1 and myprovider [Using PactBrokerSource(host=${pact.broker.host}, port=443, scheme=https, pacts={...}] Given state a request returns a response which has status code 400 (OK) has a matching body (OK) In the pacts section of that second line, I get repeating content for all six consumer services in the test output for each of the 17 tests, even though each of those tests is being run for one consumer. This is making the output much bigger than I was expecting. Is that intentional as I only expected to see output for the consumer specified at the start of the output (in this case myconsumer1)? I've added the full output from one test as a snippet.

uglyog
2020-04-15 23:13
Can you raise an issue for that?

uglyog
2020-04-15 23:14
Can you raise an issue for that?

uglyog
2020-04-15 23:15
We should definitely clean it up

chandanakurumeti27
2020-04-16 07:33
has joined #pact-jvm

wesleythomaswilliams
2020-04-16 10:27
@uglyog Just going through updating documentation of our pact solution for our team and one thing I'm curious about is a difference I have in my REST and Messaging provider tests. Both include this code: ``` @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); }``` However, my REST tests are annotated with `@State`, while my Messaging tests are annotated with `@PactVerifyProvider`. Is that the correct way to do things and if so, why?

uglyog
2020-04-16 22:50
`@State` is for annotating provider state callbacks. You can use them for both types of tests. `@PactVerifyProvider` is for annotating methods that return the response body. These are mainly used for message interactions.

aliihlail
2020-04-16 23:18
```package de.mediciliving.cloud.owner.pactTesting; import http://au.com.dius.pact.provider.junit.Consumer; import http://au.com.dius.pact.provider.junit.IgnoreNoPactsToVerify; import http://au.com.dius.pact.provider.junit.Provider; import http://au.com.dius.pact.provider.junit.State; import http://au.com.dius.pact.provider.junit.loader.PactBroker; import http://au.com.dius.pact.provider.junit.loader.PactBrokerAuth; import http://au.com.dius.pact.provider.junit5.PactVerificationContext; import http://au.com.dius.pact.provider.spring.junit5.PactVerificationSpringProvider; import org.junit.jupiter.api.TestTemplate; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) @ActiveProfiles("test") @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @Provider("operator-service") @Consumer("document-service") @PactBroker(authentication = @PactBrokerAuth(token = "${pactbroker.auth.token}"), scheme = "${pactbroker.scheme}", port = "${pactbroker.port}", host = "${pactbroker.host}") @IgnoreNoPactsToVerify public class OwnerVerificationTest { @TestTemplate @ExtendWith(PactVerificationSpringProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { if (context != null) { context.verifyInteraction(); } } @State("operator with id 1 exist") public void documentServiceTest() { } }```

aliihlail
2020-04-16 23:19
im writing this small testing code but ia got this error

aliihlail
2020-04-16 23:19
java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) at http://au.com.dius.pact.provider.spring.junit5.PactVerificationSpringProvider.getValueResolver(PactVerificationSpringProvider.kt:16) at http://au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider.resolvePactSources(PactJUnit5VerificationProvider.kt:395) at http://au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider.provideTestTemplateInvocationContexts(PactJUnit5VerificationProvider.kt:366) at org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor.lambda$execute$0(TestTemplateTestDescriptor.java:97) at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:271) at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497) at org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor.execute(TestTemplateTestDescriptor.java:101) at org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor.execute(TestTemplateTestDescriptor.java:38) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:112) at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$2(HierarchicalTestExecutor.java:120) at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177) at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133) at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:120) at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$2(HierarchicalTestExecutor.java:120) at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177) at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133) at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:120) at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:55) at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:43) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58) Caused by: java.lang.IllegalStateException: Logback configuration error detected: ERROR in ch.qos.logback.core.joran.action.AppenderRefAction - Could not find an appender named [LOG_APPENDER_IS_UNDEFINED]. Did you define it below instead of above in the configuration file? ERROR in ch.qos.logback.core.joran.action.AppenderRefAction - See http://logback.qos.ch/codes.html#appender_order for more details. at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:169) at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:82) at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60) at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:117) at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:264) at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:237) at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:200) at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:173) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74) at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:338) at org.springframework.boot.SpringApplication.run(SpringApplication.java:297) at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:137) at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:208) at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:104) at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:70) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74) at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:338) at org.springframework.boot.SpringApplication.run(SpringApplication.java:297) at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:127) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) ... 58 more

aliihlail
2020-04-16 23:19
Can any one assist me how to handle this issue

uglyog
2020-04-16 23:29
> Logback configuration error detected: This is nothing to do with Pact, but your Spring/Logback configuration that is wrong

chandanakurumeti27
2020-04-17 09:41
Hello @RunWith(PactRunner.class) @Provider("playerservice") @PactFolder("pacts") public class IfProviderTest { @TestTarget public final Target target = new HttpTarget("http", "127.0.0.1:10001", 443, "/frontend/api"); @TargetRequestFilter public void exampleRequestFilter(HttpRequest request) { request.addHeader("Content-Length", "84"); } }

chandanakurumeti27
2020-04-17 09:43
so this is the simple pact jvm providr junit test of mine looks like

chandanakurumeti27
2020-04-17 09:43
when am running this:I got the below error, not sure what am actually missing here:

chandanakurumeti27
2020-04-17 09:44
error: java.lang.NullPointerException: Cannot invoke method split() on null object at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:35) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) at http://au.com.dius.pact.provider.reporters.AnsiConsoleReporter.displayError(AnsiConsoleReporter.groovy:226) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:384) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:69) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166) at http://au.com.dius.pact.provider.reporters.AnsiConsoleReporter$_displayFailures_closure1.doCall(AnsiConsoleReporter.groovy:187) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021) at groovy.lang.Closure.call(Closure.java:426) at org.codehaus.groovy.runtime.DefaultGroovyMethods.callClosureForMapEntryAndCounter(DefaultGroovyMethods.java:5245) at org.codehaus.groovy.runtime.DefaultGroovyMethods.eachWithIndex(DefaultGroovyMethods.java:2155) at org.codehaus.groovy.runtime.dgm$175.invoke(Unknown Source) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:274) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) at http://au.com.dius.pact.provider.reporters.AnsiConsoleReporter.displayFailures(AnsiConsoleReporter.groovy:184) at http://au.com.dius.pact.provider.reporters.VerifierReporter$displayFailures$3.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) at http://au.com.dius.pact.provider.ProviderVerifier$_displayFailures_closure33.doCall(ProviderVerifier.groovy:394) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021) at groovy.lang.Closure.call(Closure.java:426) at groovy.lang.Closure.call(Closure.java:442) at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2030) at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2015) at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2056) at org.codehaus.groovy.runtime.dgm$162.invoke(Unknown Source) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:274) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) at http://au.com.dius.pact.provider.ProviderVerifier.displayFailures(ProviderVerifier.groovy:394) at au.com.dius.pact.provider.junit.target.HttpTarget.testInteraction(HttpTarget.java:114) at http://au.com.dius.pact.provider.junit.InteractionRunner$2.evaluate(InteractionRunner.java:183) at au.com.dius.pact.provider.junit.InteractionRunner.run(InteractionRunner.java:143) at http://au.com.dius.pact.provider.junit.PactRunner.runChild(PactRunner.java:100) at http://au.com.dius.pact.provider.junit.PactRunner.runChild(PactRunner.java:48) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

chandanakurumeti27
2020-04-17 09:44
I made sure,i have pact file in test/resources/pact and can see that test can pick up the pact file

chandanakurumeti27
2020-04-17 09:45
Please help me to resolve this issue

chandanakurumeti27
2020-04-17 10:27
Please ignore the above message as its resolved after I adjusted the dependency versions. Sorry for you time if you already spent some. Thank you!

komeershettyvinod
2020-04-17 11:01
hi

komeershettyvinod
2020-04-17 11:01
I am using gradle as provider for my pacts

komeershettyvinod
2020-04-17 11:01
and I am seeing below error No such property: isDependencyForPactVerify for class: http://au.com.dius.pact.provider.gradle.GradleProviderInfo Possible solutions: dependencyForPactVerify

komeershettyvinod
2020-04-17 11:01
I could not understand rarely whats wrong with my gradle file

komeershettyvinod
2020-04-17 11:21
//import com.github.jengelman.gradle.plugins.processes.tasks.JavaFork buildscript { repositories { maven { url "https://repo.grails.org/grails/core" } } dependencies { classpath "org.grails:grails-gradle-plugin:$grailsVersion" classpath "org.grails.plugins:hibernate5:7.0.0" classpath "gradle.plugin.com.github.erdi.webdriver-binaries:webdriver-binaries-gradle-plugin:2.0" classpath "com.bertramlabs.plugins:asset-pipeline-gradle:3.0.10" classpath "org.grails.plugins:views-gradle:2.0.0.BUILD-SNAPSHOT" classpath("com.github.jengelman.gradle.plugins:gradle-processes:0.3.0") //Producer side dependencies classpath("au.com.dius:pact-jvm-provider-gradle_2.11:3.5.0") classpath("com.github.jengelman.gradle.plugins:gradle-processes:0.3.0") } } plugins { id "http://au.com.dius.pact" version "4.0.0" } version "0.1" group "studentservice" apply plugin:"eclipse" apply plugin:"idea" apply plugin:"war" apply plugin:"org.grails.grails-web" apply plugin:"com.github.erdi.webdriver-binaries" apply plugin:"org.grails.grails-gsp" apply plugin:"com.bertramlabs.asset-pipeline" apply plugin:"org.grails.plugins.views-json" //Producer side plugins //apply plugin: 'http://au.com.dius.pact' apply plugin: 'com.github.johnrengelman.processes' repositories { maven { url "https://repo.grails.org/grails/core" } } configurations { developmentOnly runtimeClasspath { extendsFrom developmentOnly } } dependencies { developmentOnly("org.springframework.boot:spring-boot-devtools") compile "org.springframework.boot:spring-boot-starter-logging" compile "org.springframework.boot:spring-boot-autoconfigure" compile "org.grails:grails-core" compile "org.springframework.boot:spring-boot-starter-actuator" compile "org.springframework.boot:spring-boot-starter-tomcat" compile "org.grails:grails-web-boot" compile "org.grails:grails-logging" compile "org.grails:grails-plugin-rest" compile "org.grails:grails-plugin-databinding" compile "org.grails:grails-plugin-i18n" compile "org.grails:grails-plugin-services" compile "org.grails:grails-plugin-url-mappings" compile "org.grails:grails-plugin-interceptors" compile "org.grails.plugins:cache" compile "org.grails.plugins:async" compile "org.grails.plugins:scaffolding" compile "org.grails.plugins:events" compile "org.grails.plugins:hibernate5" compile "org.hibernate:hibernate-core:5.4.0.Final" compile "org.grails.plugins:gsp" compileOnly "io.micronaut:micronaut-inject-groovy" console "org.grails:grails-console" profile "org.grails.profiles:web" runtime "org.glassfish.web:el-impl:2.1.2-b03" runtime "com.h2database:h2" runtime "org.apache.tomcat:tomcat-jdbc" runtime "javax.xml.bind:jaxb-api:2.3.0" runtime "com.bertramlabs.plugins:asset-pipeline-grails:3.0.10" testCompile "org.grails:grails-gorm-testing-support" testCompile "org.mockito:mockito-core" testCompile "org.grails:grails-web-testing-support" testCompile "org.grails.plugins:geb" testCompile "org.seleniumhq.selenium:selenium-remote-driver:3.14.0" testCompile "org.seleniumhq.selenium:selenium-api:3.14.0" testCompile "org.seleniumhq.selenium:selenium-support:3.14.0" testRuntime "org.seleniumhq.selenium:selenium-chrome-driver:3.14.0" testRuntime "org.seleniumhq.selenium:selenium-firefox-driver:3.14.0" compile "org.grails.plugins:views-json" compile "org.grails.plugins:views-json-templates" compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7' testCompile 'au.com.dius:pact-jvm-consumer-groovy_2.11:3.5.0' testCompile 'au.com.dius:pact-jvm-consumer-junit_2.11:3.5.0' } bootRun { jvmArgs( '-Dspring.output.ansi.enabled=always', '-noverify', '-XX:TieredStopAtLevel=1', '-Xmx1024m') sourceResources sourceSets.main String springProfilesActive = 'spring.profiles.active' systemProperty springProfilesActive, System.getProperty(springProfilesActive) } webdriverBinaries { chromedriver '2.45.0' geckodriver '0.24.0' } tasks.withType(Test) { systemProperty "geb.env", System.getProperty('geb.env') systemProperty "geb.build.reportsDir", reporting.file("geb/integrationTest") systemProperty "webdriver.chrome.driver", System.getProperty('webdriver.chrome.driver') systemProperty "webdriver.gecko.driver", System.getProperty('webdriver.gecko.driver') } assets { minifyJs = true minifyCss = true } test { systemProperties['pact.rootDir'] = "$buildDir/pacts" } // This will be called before the provider task task('startTheApp') { doFirst { // start up your provider here classpath = sourceSets.main.runtimeClasspath //// main = 'com.github.felipecao.pactsample.producer.Application' main = 'studentservice.Application' } doLast { Thread.sleep(15000) // time Spring Boot takes to start } } // This will be called after the provider task //task killTheApp{ // doLast { // // kill your provider here // // startTheApp.processHandle.abort() // // } //} pact { serviceProviders { StudentProducer { // dependencyForPactVerify = false protocol = 'http' host = 'localhost' port = 8080 path = '/' startProviderTask = startTheApp // terminateProviderTask = killTheApp hasPactWith('StudentConsumer1') { pactFile = file('target/pacts/StudentConsumer1-StudentProducer.json') } } } } //task startProducer(type: JavaFork) { //// classpath = sourceSets.main.runtimeClasspath ////// main = 'com.github.felipecao.pactsample.producer.Application' //// main = 'studentservice.Application' //// doLast { //// Thread.sleep(15000) // time Spring Boot takes to start //// } ////} ////task stopProducer << { //// startProducer.processHandle.abort() ////}

komeershettyvinod
2020-04-17 11:21
My gradle files looks like

darshan
2020-04-17 16:27
has joined #pact-jvm

uglyog
2020-04-18 04:35
You shouldn't modify the content length header, it will be set based on the size of the body.

uglyog
2020-04-18 04:40
You're mixing different versions of Pact-JVM. You have ```classpath("au.com.dius:pact-jvm-provider-gradle_2.11:3.5.0")``` as well as ```plugins { id "http://au.com.dius.pact" version "4.0.0" }```

uglyog
2020-04-18 04:41
You should try the latest version for both (4.0.9)

uglyog
2020-04-18 04:41
```plugins { id "http://au.com.dius.pact" version "4.0.9" }```

uglyog
2020-04-18 04:42
```classpath("au.com.dius:pact-jvm-provider-gradle:4.0.9")```

aliihlail
2020-04-19 10:56
I wrote a test code for both Assync and http Get request. the code is runnib and testing perfictly. but when i run mvn pact:verify i got this error. any help please `[ERROR] Failed to execute goal au.com.dius:pact-jvm-provider-maven:4.0.8:verify (default-cli) on project contact-service: A type incompatibility occurred while executing au.com.dius:pact-jvm-provider-maven:4.0.8:verify: class http://au.com.dius.pact.core.model.messaging.Message cannot be cast to class http://au.com.dius.pact.core.model.RequestResponseInteraction (http://au.com.dius.pact.core.model.messaging.Message and http://au.com.dius.pact.core.model.RequestResponseInteraction are in unnamed module of loader org.codehaus.plexus.classworlds.realm.ClassRealm @7fad214a)`

jayeshdalal7
2020-04-19 12:29
has joined #pact-jvm

uglyog
2020-04-19 22:27
Are you able to share your test and pact file?

chandanakurumeti27
2020-04-20 09:46
Yeah, I just randomly picked the "Content-Lendth" header to see how request filters are working. and ended up with error which says ,content length is already exists. So came to know that i shouldnt change contentlength header using request filter. :slightly_smiling_face:

chandanakurumeti27
2020-04-20 09:46
Anyways, Thank you so much for responding! Have a nice monday!

paras.vora1801
2020-04-20 13:35
Hello, below is the DEBUG log for my pact verification result: `Verifying a pact between ceapi and auth_server` `[from Pact Broker http://localhost/pacts/provider/auth_server/consumer/ceapi/version/1.0.100]` `Given A valid authorization token is returned` `WARNING: State Change ignored as there is no stateChange URL` `[DEBUG] State Change: "ProviderState(name=A valid authorization token is returned, params={})" -> Ok(value={})` `A request to fetch the authorization token` `[DEBUG] Verifying via request/response` `[DEBUG] Making request for provider http://au.com.dius.pact.provider.maven.Provider@f3b3f2c[name=auth_server,protocol=http,host=localhost,port=8080,path=/,startProviderTask=<null>,terminateProviderTask=<null>,requestFilter=<null>,stateChangeRequestFilter=<null>,createClient=<null>,insecure=false,trustStore=<null>,trustStorePassword=changeit,stateChangeUrl=<null>,stateChangeUsesBody=true,stateChangeTeardown=false,isDependencyForPactVerify=true,verificationType=REQUEST_RESPONSE,packagesToScan=[],consumers=[ConsumerInfo(name='ceapi', stateChange=null, stateChangeUsesBody=true, packagesToScan=[], verificationType=null, pactSource=BrokerUrlSource(url=http://localhost/pacts/provider/auth_server/consumer/ceapi/version/1.0.100, pactBrokerUrl=http://localhost:80, attributes={}, options={}, tag=null), pactFileAuthentication=[basic, pact_workshop, pact_workshop])],pactFileDirectory=<null>,pactBrokerUrl=<null>,pactBroker=PactBroker(url=http://localhost:80, tags=[], authentication=PactBrokerAuth(scheme=basic, token=null, username=pact_workshop, password=pact_workshop), serverId=null),pactFileDirectories=[],name=provider,protocol=http,host=localhost,port=8080,path=/,startProviderTask=<null>,terminateProviderTask=<null>,requestFilter=<null>,stateChangeRequestFilter=<null>,createClient=<null>,insecure=false,trustStore=<null>,trustStorePassword=changeit,stateChangeUrl=<null>,stateChangeUsesBody=true,stateChangeTeardown=false,isDependencyForPactVerify=true,verificationType=REQUEST_RESPONSE,packagesToScan=[],consumers=[ConsumerInfo(name='ceapi', stateChange=null, stateChangeUsesBody=true, packagesToScan=[], verificationType=null, pactSource=BrokerUrlSource(url=http://localhost/pacts/provider/auth_server/consumer/ceapi/version/1.0.100, pactBrokerUrl=http://localhost:80, attributes={}, options={}, tag=null), pactFileAuthentication=[basic, pact_workshop, pact_workshop])]]:` `[DEBUG] method: POST` `path: /oauth-server/oauth/token` `query: {}` `headers: {Authorization=[Basic Y2VhcGlDbGllbnRJZDpjZWFwaUNsaWVudFNlY3JldA==], Content-Type=[application/x-www-form-urlencoded; charset=utf-8]}` `matchers: MatchingRules(rules={})` `generators: Generators(categories={})` `body: PRESENT(client_id=ceapiClientId&grant_type=client_credentials)` `Request Failed - Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)` `[WARNING] Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true')` `Failures:` `0) Verifying a pact between ceapi and auth_server - A request to fetch the authorization token Given A valid authorization token is returned` `Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)`

paras.vora1801
2020-04-20 13:37
It seems that the request is going is being made assuming the server is spawned to localhost:8080

paras.vora1801
2020-04-20 13:37
Whereas, in my test I have given the configuration as: ```@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)```

paras.vora1801
2020-04-20 13:38
I am verifying the pact via `mvn pact:verify`

paras.vora1801
2020-04-20 13:41
```<plugin> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>4.0.9</version> <configuration> <serviceProviders> <serviceProvider> <name>auth_server</name> <pactBroker> <url>http://localhost:80</url> <authentication> <scheme>basic</scheme> <username>pact_workshop</username> <password>pact_workshop</password> </authentication> </pactBroker> </serviceProvider> </serviceProviders> </configuration> </plugin>```

paras.vora1801
2020-04-20 13:41
This is how the pom.xml plugin looks like.

paras.vora1801
2020-04-20 13:42
Any idea why it is always pointing to localhost:8080?

wesleythomaswilliams
2020-04-20 13:52
@paras.vora1801 In your provider test, what have you set your target as: ```@BeforeEach void setupTestTarget(PactVerificationContext context) { context.setTarget(???); }```


paras.vora1801
2020-04-20 13:59
```@RunWith(SpringRestPactRunner.class) @Provider("auth_server") //@PactFolder("/Users/paras.vora/n_workspace/rt/customer-eapi/target/pacts") @PactBroker( host = "localhost", port = "80", authentication = @PactBrokerAuth(username = "pact_workshop", password = "pact_workshop")) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) //@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) //@Ignore public class ProviderTests { @Before public void setUp() { System.out.println("Runs before the Service boot"); } @State("A valid authorization token is returned") public void getAuthToken() { System.out.println("I am in test"); } @TestTarget public final Target target = new SpringBootHttpTarget(); }```

paras.vora1801
2020-04-20 14:00
I have set the TestTarget using the annotation.

paras.vora1801
2020-04-20 14:16
Catch here is, when I run the test from the class, then it points to the desired server url which is not the case when I do is via command line `mvn pact:verify`

wesleythomaswilliams
2020-04-20 14:52
@paras.vora1801 I remember having a similar issue (https://pact-foundation.slack.com/archives/C9UN99H24/p1578589599016300), but ultimately didn't need to execute `mvn pact:verify`. We ended up removing use of `pact-jvm-provider-maven` from our pom and removed @RunWith(SpringRestPactRunner.class), so we run with junit and just provide any required properties via the surefire plugin as follows: ``` <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <systemPropertyVariables> <pact.provider.version>${pact.provider.version}</pact.provider.version> <pact.broker.host>http://pde.pact.dius.com.au</pact.broker.host> <pact.broker.token>********</pact.broker.token> </systemPropertyVariables> </configuration> </plugin>``` I'll send you my test class in a DM

wesleythomaswilliams
2020-04-20 14:53
@paras.vora1801 This from @uglyog (the expert here) set me on my path: ```The JUnit Spring test framework is starting your provider before running your test. If you want to use the Maven plugin to run the verification, you need to have your provider started before it runs. One way of doing that is to use the integration test phase, which has a pre- and post- phase that can be used to start and stop your provider. You'll ned to work out how to bind the pact plugin to the integration test phase and find a plugin that can start your provider in the pre-integration-test phase. I would recommend using JUnit tests, though. You don't have to worry about starting and stopping the provider then.```

komeershettyvinod
2020-04-20 17:08
Hi I am writing a pact-jvm groovy consumer test

komeershettyvinod
2020-04-20 17:08
I have service where i give input firstName & lastName as part of json input

komeershettyvinod
2020-04-20 17:09
the o/p is json body: firstName, lastName and lastUpdated which returns in format of "2020-04-20T15:04:24Z"

komeershettyvinod
2020-04-20 17:09
But I could not apply timestampmatchers

komeershettyvinod
2020-04-20 17:10
correctly

komeershettyvinod
2020-04-20 17:10
It always fails at assertion error

komeershettyvinod
2020-04-20 17:10
can you please how to apply patterns

komeershettyvinod
2020-04-20 17:12
package studentservice //import http://au.com.dius.pact.consumer.Pact import http://au.com.dius.pact.consumer.PactVerificationResult import http://au.com.dius.pact.consumer.groovy.PactBuilder import http://au.com.dius.pact.model.Pact import http://au.com.dius.pact.model.matchingrules.MatchingRuleGroup import http://au.com.dius.pact.model.matchingrules.RegexMatcher import http://au.com.dius.pact.model.matchingrules.TimeMatcher import http://au.com.dius.pact.model.matchingrules.TimestampMatcher //import http://au.com.dius.pact.core.model.matchingrules.TimestampMatcher import http://groovyx.net.http.RESTClient import org.junit.Test class StudentServiceConsumerPactTest { @Test void "Post User service test"() { PactBuilder student_service = new PactBuilder() // Create a new PactBuilder student_service { serviceConsumer "StudentConsumer1" // Define the service consumer by name hasPactWith "StudentProducer" // Define the service provider that it has a pact with port 9000 // The port number for the service. It is optional, leave it out to // to use a random one } student_service { given('test post call for with student details') // defines a provider state. It is optional. uponReceiving('student details') // upon_receiving starts a new interaction // withAttributes(method: 'post', path: '/api/v1/student', body: '{"id":22, "firstName":"vinod", "lastName":"komeershetty"}') withAttributes(method: 'post', path: '/api/v1/student') withBody { firstName 'vinod' lastName 'komeershetty' } willRespondWith( // define the response we want returned status: 200, headers: ['Content-Type': 'application/json'], // body: "{\"id\":2,\"firstName\":\"vinod\",\"lastUpdated\":\"2020-04-15T12:24:31Z\",\"lastName\":\"komeershetty\"}" // body: "{\"id\":2,\"firstName\":\"vinod\",\"lastUpdated\":\"2020-04-15T12:24:31Z\",\"lastName\":\"komeershetty\"}" body: { // id(integer) firstName("vinod") lastName("komeershetty") // lastUpdated = timestamp('yyyy/MM/dd - HH:mm:ss.S','2020-04-20T15:04:24Z') lastUpdated("2020-04-20T15:04:24Z") } ) } // Execute the run method to have the mock server run. // It takes a closure to execute your requests and returns a PactVerificationResult. PactVerificationResult result = student_service.runTest { def client = new RESTClient('http://localhost:9000/') def alice_response = http://client.post(path: '/api/v1/student', body: '{"firstName":"vinod", "lastName":"komeershetty"}', requestContentType: 'application/json',) assert alice_response.status == 200 def data = alice_response.data assert data.firstName == "vinod" assert data.lastName == "komeershetty" assert data.lastUpdated == [new TimestampMatcher('yyyy-MM-dd\'T\'HH:mm:ss')] } assert result == PactVerificationResult.Ok.INSTANCE // This means it is all good } }

komeershettyvinod
2020-04-20 17:12
Above is the sample program

paras.vora1801
2020-04-20 19:14
Hello, I am facing issues while running the provider test via command line - `mvn pact:verify` below is my provider test class. ```@RunWith(SpringRestPactRunner.class) @Provider("auth_server") @PactBroker( host = "localhost", port = "80", authentication = @PactBrokerAuth(username = "pact_workshop", password = "pact_workshop")) @SpringBootTest( classes = AuthorizationServerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = "spring.profiles.active=test") /*@SpringBootTest( classes = AuthorizationServerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, properties = "spring.profiles.active=test")*/ //@Ignore public class ProviderTests { @LocalServerPort private int port; @Before public void setUp() { System.out.println("Runs before the Service boot"); } @State("A valid authorization token is returned") public void getAuthToken() { System.out.println("I am in test"); } @TestTarget public final Target target = new SpringBootHttpTarget(); }```

paras.vora1801
2020-04-20 19:16
This code runs as an individual test class however, fails to upload the verification result to the broker from where it fetches the pacts: ```Verifying a pact between ceapi and auth_server Given A valid authorization token is returned A request to fetch the authorization token 2020-04-21 00:30:57,403 INFO [com.touchcommerce.commons.auth.db.dao.impl.ApiClientAppDaoImpl] - <Dao [com.touchcommerce.commons.auth.db.dao.impl.ApiClientAppDaoImpl] in-memory dataset was updated in [5] ms. [6] records loaded, [6] total size.> 2020-04-21 00:30:57,403 DEBUG [com.inq.auth.service.authentication.ApiClientDetailsService] - <Found client app for clientId ceapiClientId : BaseClientDetails [clientId=ceapiClientId, clientSecret=ceapiClientSecret, scope=[read, write], resourceIds=[ceapi], authorizedGrantTypes=[client_credentials], registeredRedirectUris=null, authorities=[], accessTokenValiditySeconds=60, refreshTokenValiditySeconds=null, additionalInformation={}]> returns a response which has status code 200 (OK) has a matching body (OK) 2020-04-21 00:30:57,666 WARN [http://au.com.dius.pact.provider.DefaultTestResultAccumulator] - <Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true')> HttpAdaptor version 3.0.1 stopped on port 9090```

paras.vora1801
2020-04-20 19:18
@matt.fellows /@uglyog How can I make this run via command line?, I plan to include this command line into the jenkins pipeline stage.

paras.vora1801
2020-04-20 19:21
I tried using the `pact-jvm-provider-maven` plugin, below is the pom content; ```<plugin> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>4.0.9</version> <configuration> <serviceProviders> <serviceProvider> <name>auth_server</name> <pactBroker> <url>http://localhost:80</url> <authentication> <scheme>basic</scheme> <username>pact_workshop</username> <password>pact_workshop</password> </authentication> </pactBroker> </serviceProvider> </serviceProviders> </configuration> </plugin>``` dependencies used are: ```<dependency> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-spring</artifactId> <version>4.0.9</version> </dependency> <dependency> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>4.0.10</version> </dependency>``` While doing a `mvn pact:verify` this is the output: ```Verifying a pact between ceapi and auth_server [from Pact Broker http://localhost/pacts/provider/auth_server/consumer/ceapi/version/1.0.100] Given A valid authorization token is returned WARNING: State Change ignored as there is no stateChange URL A request to fetch the authorization token Request Failed - Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused) [WARNING] Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true')``` The request goes to the provider server *`localhost:8080`* which seems not available.

a.carpe
2020-04-20 20:46
has joined #pact-jvm

a.carpe
2020-04-20 21:00
Hello everybody, I?m having an issue publishing my pacts with `pact-jvm-provider-gradle` the error I receive is: ```Caused by: java.lang.NoSuchMethodError: com.google.gson.JsonParser.parseString(Ljava/lang/String;)Lcom/google/gson/JsonElement; at http://au.com.dius.pact.core.pactbroker.PactBrokerClient.uploadPactFile(PactBrokerClient.kt:184)``` The offending code is this one: ```open fun uploadPactFile(pactFile: File, unescapedVersion: String, tags: List<String> = emptyList()): Any? { val pactText = pactFile.readText() val pact = JsonParser.parseString(pactText)``` I tried to debug the task, the content of the file is there and it is a valid json. I see the `JsonParser` class and the `parseString` static method too, I can navigate with idea to the method as the dependency on `com.google.code.gson:gson:2.8.6` is there. I double checked the `build.gradle` but I wasn?t able to see anything wrong. Has anyone an idea on what?s going on?

aliihlail
2020-04-20 23:08
~can i use at the provider side for Amqp test.~ ```@TestTemplate @ExtendWith(PactVerificationSpringProvider.class) void testTemplate(Pact pact, Interaction interaction, PactVerificationContext context) { http://LOGGER.info("testTemplate called: " + pact.getProvider().getName() + ", " + interaction); context.verifyInteraction(); }```

uglyog
2020-04-20 23:12
The Maven plugin does not work with springboot. It won't know what port your app is running on. It also won't be able to start and stop your app. You are using a JUnit test, so there is no need for the plugin.

uglyog
2020-04-20 23:14
You must have a dependency issue where an older version of GSon is being loaded. Can you check your project dependencies to see what is being loaded?

a.carpe
2020-04-21 08:19
I though the same, doing a `./gradlew -q dependencies my-project:dependencies` I can find the pact dependencies only in `testCompileClasspath` and `testRuntimeClasspath` . There I found: ```+--- org.springframework.boot:spring-boot-starter-jdbc -> 2.3.0.M3 | +--- org.springframework.boot:spring-boot-dependencies:2.3.0.M3 | | +--- com.google.code.gson:gson:2.8.6 (c) +--- au.com.dius:pact-jvm-provider-spring:4.0.10 | \--- au.com.dius:pact-jvm-provider-junit:4.0.10 | +--- au.com.dius:pact-jvm-core-support:4.0.10 | | +--- com.google.code.gson:gson:2.8.6 | \--- au.com.dius:pact-jvm-provider:4.0.10 | +--- au.com.dius:pact-jvm-core-model:4.0.10 | | +--- au.com.dius:pact-jvm-core-pact-broker:4.0.10 | | | +--- com.github.salomonbrys.kotson:kotson:2.5.0 | | | | +--- com.google.code.gson:gson:2.8.0 -> 2.8.6 | | | +--- com.google.code.gson:gson:2.8.6 | | \--- com.google.code.gson:gson:2.8.6```

uglyog
2020-04-21 22:59
I wonder what the `(c)` means?

uglyog
2020-04-21 22:59
> com.google.code.gson:gson:2.8.6 (c)

a.carpe
2020-04-22 09:15
```(c) - dependency constraint (*) - dependencies omitted (listed previously) (n) - Not resolved (configuration is not meant to be resolved)```

uglyog
2020-04-22 22:21
Ah, that?s the class path for the tests. It?s not the classpath used by the plugin tasks. Just to confirm, are you using the same version of the gradle plugin (4.0.10)?

uglyog
2020-04-22 22:22
Can you provide what other plugins you are using?

corey
2020-04-22 22:41
has joined #pact-jvm

corey
2020-04-22 22:51
I'm attempting to upgrade a small consumer junit test that was using `pact-jvm-consumer-junit_2.11:3.5.0` to `pact-jvm-consumer-junit:4.0.10` and, after resolving some changed imports, am running into a `SocketException: Connection reset` when the consumer attempts to make a request to the mock provider. I ran the test with the debugger and hopped out into `curl` and see that I'm getting `curl: (52) Empty reply from server` . Not sure where to proceed from here

uglyog
2020-04-22 23:00
One of the issues that cause this is the version of Gson library. It needs to be 2.8.6. See https://github.com/DiUS/pact-jvm/issues/1054 and https://github.com/DiUS/pact-jvm/issues/1057

corey
2020-04-22 23:12
Upgrading gson did not resolve the issue. I may try and post an example tomorrow

aliihlail
2020-04-23 06:21
Hi, im trying to test amqp messages and one Drawback is that auto-filling the pactbroker-auth data from application.properties won't work anymore. this is appeared when i use @ExtendWith(PactVerificationInvocationContextProvider.class). any idea how to overccome this issue

uglyog
2020-04-23 06:28
Was the auto-filling done by Spring?

aliihlail
2020-04-23 06:32
yes.

uglyog
2020-04-23 06:34
And why can't you use Spring for this test?

aliihlail
2020-04-23 06:34
but with PactVerificationInvocationContextProvider no. and i dont need to use Spring Application Context

aliihlail
2020-04-23 06:34
it slow. and i have to write more ccode

aliihlail
2020-04-23 06:35
code. and i would stick with PactVerificationInvocationContextProvider.

uglyog
2020-04-23 06:35
Well, you will have to configure the broker in a different manner, because to get Spring to inject those values you need to start a Spring context

aliihlail
2020-04-23 06:36
how

uglyog
2020-04-23 06:36
You can use JVM system properties

a.carpe
2020-04-23 15:26
Yes I?m using the same version of the gradle plugin. here is the plugins? list: ```apply plugin: 'kotlin' apply plugin: 'kotlin-spring' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' apply plugin: 'org.flywaydb.flyway' apply plugin: 'http://au.com.dius.pact'``` and this is the dependecies inside the `buildscript` ```dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}") classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}") classpath "org.flywaydb:flyway-gradle-plugin:${flywayVersion}" classpath "au.com.dius:pact-jvm-provider-gradle:${pactVersion}" }``` where `pactVersion` is `4.0.10`

a.carpe
2020-04-23 15:38
I?m not able to find a command to list the classPath used by plugins to check the dependencies used by the plugin?

a.carpe
2020-04-23 16:04
I managed to make it works!

corey
2020-04-23 16:08
Dug in more this morning and the issue was around Kotlin version as pointed out in issue 949. Thanks Spring /sarcasm

a.carpe
2020-04-23 16:08
my app is structured in this way: ```+---my-app | +---my-app-domain | | \---build.gradle | +---my-app-web | | \---build.gradle | \---build.gradle``` because all my contract tests are under `my-app-web` I placed all the dependencies and the plugin configuration under the `my-app-web`?s `build.gradle` . Than I thought? ?I?m running gradle from the root folder? let me try to move only the plugin configuration on the root?s `build.gradle` ? and boom! It worked!

asher.feil
2020-04-23 19:31
has joined #pact-jvm

asher.feil
2020-04-23 19:37
Hi there, I'm trying to test out publishing a pact to a broker. But when I run the pactPublish task I just get this exception `Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)` I'm using au.com.dius:pact-jvm-provider-gradle:4.0.9 and the pact config isn't much ```pact { publish { pactBrokerUrl = myBrokerUrl version = '1.1.0' } }```

asher.feil
2020-04-23 19:39
that sent a little before I was done. I'm wondering if there is more required in the pact config for it to work or if the issue might lie outside of the plugin config. The pact are stored in the default directory so I left that option off.

uglyog
2020-04-23 22:36
what versions of Gradle and Java are you using?

asher.feil
2020-04-23 23:00
java 11 gradle 5.6.2

uglyog
2020-04-23 23:03
You might need to find any Gradle logs. There may be a stack trace logged somewhere to indicate why the Gradle deamon died

asher.feil
2020-04-24 00:15
thanks! it seems to be a similar issue to this one https://github.com/DiUS/pact-jvm/issues/414 with the root cause being jansi. the link you posted at the bottom doesn't seem to work now, though. FWIW unlike the description in that issue, I'm not doing this in docker


uglyog
2020-04-24 00:25
Apart from using docker, does the info in that issue help?

asher.feil
2020-04-24 00:59
i tried changing the reports to not include console, but i think the issue is on AnsiConsole init so thats not going to do it. looking at the linked issues, seems like there were work around but they stopped functioning?

asher.feil
2020-04-24 03:19
any other thoughts on workarounds?

mbieganski.infomatt
2020-04-24 12:40
has joined #pact-jvm

aliihlail
2020-04-26 21:50
@ActiveProfiles("test") @Provider("key-service") @Consumer("document-service") @PactBroker( authentication = @PactBrokerAuth(token = "${pactbroker.auth.token}"), scheme = "https", port = "443", host = "${pactbroker.auth.host}") @IgnoreNoPactsToVerify public class DocumentVerificationTest { private static final Logger LOGGER = LoggerFactory.getLogger(DocumentVerificationTest.class); @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void testTemplate(Pact pact, Interaction interaction, PactVerificationContext context) throws IOException { http://LOGGER.info("testTemplate called: " + pact.getProvider().getName() + ", " + interaction); context.verifyInteraction(); } @BeforeEach void setupTestTarget(PactVerificationContext context) throws IOException { context.setTarget(new AmpqTestTarget()); } @PactVerifyProvider("key handover") public Object documentServiceTest() { KeyProtocol keyProtocol = TestKeyFactory.createKeyProtocol(); keyProtocol.setId(1L); keyProtocol.setHandoverNote("test HandoverNote"); keyProtocol.setStatus(KeyProtocolStatus.PENDING_ISSUED); MessageModel model = new MessageModel("key-service", "key-service", keyProtocol); JsonNode messageModel = JacksonUtil.toJsonTree(model); return messageModel; } @PactVerifyProvider("key return") public Object documentServiceTest2() { KeyProtocol keyProtocol = TestKeyFactory.createKeyProtocol(); keyProtocol.setId(1L); keyProtocol.setReturnNote("test return Note"); keyProtocol.setStatus(KeyProtocolStatus.PENDING_CLOSING); MessageModel model = new MessageModel("key-service", "key-service", keyProtocol); JsonNode messageModel = JacksonUtil.toJsonTree(model); return messageModel; } @State("KEY_SERVICE_KEY_PROTOCOL_STATUS_PENDING_ISSUED") public void someProviderState() { http://LOGGER.info("document service provider state callback"); } @State("KEY_SERVICE_KEY_PROTOCOL_STATUS_PENDING_CLOSING") public void someProviderState2() { http://LOGGER.info("document service provider state callback"); } } Hi im still new with Pact testing, Im trying to write this code for testing Amqp. when i use the PactVerificationInvocationContextProvider i got an error java.lang.RuntimeException: Could not resolve property "pactbroker.auth.host" in the system properties or environment variables and no default value is supplied the idea how to inject the hosta nd token without using spring. is their any available example. i tried to to write a propertyReader class but also i cant do it because it should be constant. I would appreciate it if any one help with how to overcome it and solve it.

uglyog
2020-04-26 22:56
How are you running the test? Using Gradle or Maven?

aliihlail
2020-04-26 23:05
MAven

aliihlail
2020-04-26 23:05
Maven

aliihlail
2020-04-26 23:07
and as you know @uglyog using Spring for testing Amqp is much slower.

uglyog
2020-04-26 23:10
Using Maven you can either pass the values on the command line (`-Dpactbroker.auth.host=http://...`) or you can configure them using the surefire plugin (it's what runs the tests in Maven)

aliihlail
2020-04-26 23:18
can i add them to the application properties and then use a propertyReader, I tried but i got an error that it should be constant.

uglyog
2020-04-26 23:29
You can't use propertyReader, because you are not loading a Spring context. The only options you have is to use the command line parameters or set the properties on the surefire plugin.

aliihlail
2020-04-26 23:32
So can i understand that those the only 2 way and only those. can you also link me to an example of how to use them. i mean ether surefire pluging or the command line

aliihlail
2020-04-26 23:43
when i use the surefire plugin i got the following error java.lang.UnsupportedOperationException: At least one pact source must be present on the test class

uglyog
2020-04-26 23:52
There is something wrong with your setup, because it's not seeing the `@PactBroker` as a pact source. Can you confirm the full class for that annotation?

aliihlail
2020-04-26 23:54
when i added the @PactBrocker i got the follwoing error java.lang.IllegalArgumentException: Invalid pact broker host specified ('${pactbroker.host:}'). Please provide a valid host or specify the system property 'pactbroker.host'.

aliihlail
2020-04-26 23:55
im using thuis Suriefire configuration ```<plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> </plugin> <plugin> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>4.0.0</version> <configuration> <serviceProviders> <serviceProvider> <name>key-service</name> <protocol>http</protocol> <host>localhost</host> <port>8080</port> <path>/</path> <pactBroker> <url>https://XXXXX.pact.dius.com.au:443/</url> <authentication> <scheme>Bearer</scheme> <token>1-X-XXXXXXXXX</token> </authentication> </pactBroker> </serviceProvider> </serviceProviders> <pactBrokerUrl/> </configuration> </plugin>```

uglyog
2020-04-27 00:09
You can try using the latest version of the Maven plugin (4.0.10)

aliihlail
2020-04-27 00:14
java.lang.IllegalArgumentException: Invalid pact broker host specified ('${pactbroker.host:}'). Please provide a valid host or specify the system property 'pactbroker.host'.

aliihlail
2020-04-27 00:15
@uglyog and here is what i changed ``` @ActiveProfiles("test") @Provider("key-service") @Consumer("document-service") @PactBroker() public class DocumentVerificationTest {```

aliihlail
2020-04-27 00:17
i already tried also version 4.0.10

uglyog
2020-04-27 00:25
And did you run it with `-Dpactbroker.host=...`)

aliihlail
2020-04-27 10:26
No i did not tried. but i assume that this confugration should work.

aliihlail
2020-04-27 10:31
``` @ActiveProfiles("test") @Provider("key-service") @Consumer("document-service") @PactBroker @IgnoreNoPactsToVerify public class DocumentVerificationTest { private static final Logger LOGGER = LoggerFactory.getLogger(DocumentVerificationTest.class); @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void testTemplate(Pact pact, Interaction interaction, PactVerificationContext context) throws IOException { http://LOGGER.info("testTemplate called: " + pact.getProvider().getName() + ", " + interaction); context.verifyInteraction(); } @BeforeEach void setupTestTarget(PactVerificationContext context) throws IOException { context.setTarget(new AmpqTestTarget()); } @PactVerifyProvider("key handover") public Object documentServiceTest() { KeyProtocol keyProtocol = TestKeyFactory.createKeyProtocol(); keyProtocol.setId(1L); keyProtocol.setHandoverNote("test HandoverNote"); keyProtocol.setStatus(KeyProtocolStatus.PENDING_ISSUED); MessageModel model = new MessageModel("key-service", "key-service", keyProtocol); JsonNode messageModel = JacksonUtil.toJsonTree(model); return messageModel; } @PactVerifyProvider("key return") public Object documentServiceTest2() { KeyProtocol keyProtocol = TestKeyFactory.createKeyProtocol(); keyProtocol.setId(1L); keyProtocol.setReturnNote("test return Note"); keyProtocol.setStatus(KeyProtocolStatus.PENDING_CLOSING); MessageModel model = new MessageModel("key-service", "key-service", keyProtocol); JsonNode messageModel = JacksonUtil.toJsonTree(model); return messageModel; } @State("KEY_SERVICE_KEY_PROTOCOL_STATUS_PENDING_ISSUED") public void someProviderState() { http://LOGGER.info("document service provider state callback"); } @State("KEY_SERVICE_KEY_PROTOCOL_STATUS_PENDING_CLOSING") public void someProviderState2() { http://LOGGER.info("document service provider state callback"); } }```

aliihlail
2020-04-27 10:31
here is the code which also wrote on the provider side

aliihlail
2020-04-27 10:31
``` <plugin> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>4.0.10</version> <configuration> <serviceProviders> <serviceProvider> <name>key-service</name> <pactBroker> <url>https://XXXXXXXX.pact.dius.com.au:443</url> <authentication> <scheme>bearer</scheme> <token>1-A-XXXXXX</token> </authentication> </pactBroker> </serviceProvider> </serviceProviders> </configuration> </plugin>```

aliihlail
2020-04-27 10:32
and this is the suriefire plugin. i got always the same error. java.lang.IllegalArgumentException: Invalid pact broker host specified ('${pactbroker.host:}'). Please provide a valid host or specify the system property 'pactbroker.host'.

aliihlail
2020-04-27 22:27
``` @ActiveProfiles("test") @Provider("key-service") @Consumer("document-service") @PactBroker @IgnoreNoPactsToVerify public class DocumentVerificationTest { private static final Logger LOGGER = LoggerFactory.getLogger(DocumentVerificationTest.class); @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void testTemplate(Pact pact, Interaction interaction, PactVerificationContext context) throws IOException { http://LOGGER.info("testTemplate called: " + pact.getProvider().getName() + ", " + interaction); context.verifyInteraction(); } @BeforeEach void setupTestTarget(PactVerificationContext context) throws IOException { context.setTarget(new AmpqTestTarget()); } ---------------------- <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> </plugin> <plugin> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>4.0.10</version> <configuration> <serviceProviders> <serviceProvider> <name>key-service</name> <pactBroker> <url>https://XXXXXXX.pact.dius.com.au:443/</url> <authentication> <scheme>bearer</scheme> <token>1-A-XXXXXXXXXXX</token> </authentication> </pactBroker> </serviceProvider> </serviceProviders> </configuration> </plugin> Im trying to run the code which i have cut part of it above. when i use the Spring it works. But when i use @ExtendWith(PactVerificationInvocationContextProvider.class)``` i got the following error : java.lang.IllegalArgumentException: Invalid pact broker host specified ('${pactbroker.host:}'). Please provide a valid host or specify the system property 'pactbroker.host'.

uglyog
2020-04-27 22:54
I've already explained this to you. ```Please provide a valid host or specify the system property 'pactbroker.host'``` means exactly that. You need to provide this value as a JVM system property. There are two ways you can do this You can either set the value using the -D parameter when running Maven like `mvn verify -Dpactbroker.host=http://pactbroker ` (obliviously putting your host in there) OR You can configure the properties on the Maven surefire plugin. Here is a URL from Googling how to do that: http://www.javabyexamples.com/set-system-property-for-tests/

uglyog
2020-04-27 23:09
The other option is not to use system properties at all, and just set the value directly on the annotation

uglyog
2020-04-27 23:11
I.e. `@PactBroker(host = 'https://pactbroker')`

aliihlail
2020-04-27 23:45
Thanks alot this relly helped. and ever thing worked.

matt.fellows
2020-04-28 12:04
For those using Pact JVM, new guide on migrating from JUnit 4->5 https://twitter.com/kreuzwerker/status/1255057639702134784

mbieganski.infomatt
2020-04-29 04:29
Hi. Is it possible to use pending pacts and wip in junit implementation?

uglyog
2020-04-29 04:31
This hasn't been implemented yet

mbieganski.infomatt
2020-04-29 04:37
Thanks.

mbieganski.infomatt
2020-04-29 07:26
@uglyog what would be the approach for verifying pacts from feature branch with CI? Example: Consumer pushed new pact on branch feat/new and the provider webhook failed. Provider creates branch and pushes changes. What is the best appraoch for prvider CI now? 1. Have branch name match consumer branch ```pactbroker.tags="${BRANCH},master,dev"``` 2. Add latest to tags? ```pactbroker.tags='latest,master,dev'```

uglyog
2020-04-29 07:28
Was the new pact tagged with the consumer branch?

mbieganski.infomatt
2020-04-29 07:28
yes

uglyog
2020-04-29 07:29
I would go for option 1

mbieganski.infomatt
2020-04-29 07:30
will the CI fails if there is no contract to corresponding provider branch?

uglyog
2020-04-29 07:34
I'm not sure, I haven't tried that

mbieganski.infomatt
2020-04-29 07:37
will play around with it. thanks :slightly_smiling_face:

sen.rudrappa
2020-04-29 08:51
has joined #pact-jvm

mbieganski.infomatt
2020-04-29 11:06
looks like it will break build :confused: I'm wondering if there is some downside of using latest like pactbroker.tags='latest,master,dev' Unfortunately I do see yet any possibility to find consumer by tag. @bethskurrie maybe you would have have some idea :slightly_smiling_face:

mbieganski.infomatt
2020-04-29 11:41
as a workaround since I haven't found anything in Pact Broker I guess I could query database if given tag exists if not use default

bethskurrie
2020-04-29 21:04
@mbieganski.infomatt this step in our newly written CI/CD workshop explains how to verify feature pacts https://github.com/pactflow/ci-cd-workshop/blob/master/workshop/05_verifying_feature_pacts.md

bethskurrie
2020-04-29 21:05
Don't ever use "latest".

bethskurrie
2020-04-29 21:05
Also, "latest" is not actually a tag.

bethskurrie
2020-04-29 21:08
So, your option 1 (which is option 2 in that workshop) is your best approach (assuming pact JVM doesn't blow up if the tag doesn't exist) for now, because pact JVM doesn't use the APIs that allow "work in progress" pacts to be enabled yet. Once it does, you'll have the "selectors" shown in that example, but for now, your dynamic list of tags will work.

bethskurrie
2020-04-29 21:08
But I believe Ron is working on it!

bethskurrie
2020-04-29 21:13
If you're super keen, you could call the API directly to get the list of pacts, and then verify each pact individually by calling the pact verify task for each pact URL.

bethskurrie
2020-04-29 21:14
I believe pact JVM recently added support for verifying a pact at a given url (correct me if I'm wrong @uglyog)

uglyog
2020-04-29 23:29
Latest Pact-JVM does use the new endpoint

bethskurrie
2020-04-29 23:50
Ooh, exciting.

preethighalke
2020-04-30 05:51
has joined #pact-jvm

preethighalke
2020-04-30 05:53
Hi All, I have a query regarding Pact ProviderTest is this the right channel to place my query? Regards

uglyog
2020-04-30 06:09
If it's written for JVM, then yes

preethighalke
2020-04-30 06:37
Thank you @uglyog. I'm using 4.0.6 version of pact-jvm-provider-junit and seeing a RuntimeError (java.lang.NoSuchMethodError: org.junit.runners.model.TestClass.getAnnotation) as its unable to find the @PactSource , I have the following defined for my test: @RunWith(PactRunner.class) @PactFolder("src/test/resources/pacts") @Provider("xyz")

uglyog
2020-04-30 06:40
What version of JUnit are you using?

preethighalke
2020-04-30 06:40
JUnit4

uglyog
2020-04-30 06:43
I mean, what version of JUnit4?

preethighalke
2020-04-30 06:44
4.11 to be precise

uglyog
2020-04-30 06:45
You'll need to use 4.12

preethighalke
2020-04-30 06:48
ok. we are right now exploring the possibility to write contract test using pact for our product, do you have any suggestions for Pact version to beigin with?

preethighalke
2020-04-30 06:49
I just started off using 4.0.6 for Provider/Consumer. is it OK or better to shift to a greater version?

uglyog
2020-04-30 06:50
Use the latest version (4.0.10)

preethighalke
2020-04-30 06:51
sure and will that work with JUnit 4.12 ? as we cannot move to JUnit5 for now


preethighalke
2020-04-30 06:53
Many Thanks for the inputs. Regards.

mbieganski.infomatt
2020-04-30 07:17
Thank you very much . This is exactly what I thought. Since I'm using Jeknins I found a way to query broker db in pipeline and set the tags dynamically just in case pact jvm would have issue with missing tag and I will use URL functionality in webhooks.

bethskurrie
2020-04-30 07:32
Given that you have can I deploy, to emulate the "pending" feature, you could ignore all pact test failures and rely on can I deploy to report failures that affect your ability to deploy.

bethskurrie
2020-04-30 07:33
I'm pretty sure pact JVM is fine with a missing pact for a tag, as long as there is at least one pact to verify.

preethighalke
2020-04-30 10:22
With Junit version at 4.12 pact JVM version for consumer/Provider at 4.0.10 Running the provider test now throws org.junit.runners.model.InitializationError at http://au.com.dius.pact.provider.junit.PactRunner.getPactSource(PactRunner.kt:155) at http://au.com.dius.pact.provider.junit.PactRunner.initialize(PactRunner.kt:83) at http://au.com.dius.pact.provider.junit.PactRunner.getChildren(PactRunner.kt:140) at org.junit.runners.ParentRunner.getFilteredChildren(ParentRunner.java:426) I have the following annotations defined @RunWith(PactRunner.class) @PactFolder("src/test/resources/pacts") @Provider("xyz") and the pact json is very much present in the "/pacts" folder. Not sure what is amiss this time, need help as we are unable to get the ProviderTest running as a Junit. We were able to verify the generated pact using the maven plugin "pact:verify" but unable to get the simple JUnit to work. Any inputs would unblock us. Many Thanks.

jsanchez
2020-04-30 11:46
has joined #pact-jvm

komeershettyvinod
2020-04-30 12:16
I am getting 401 Unautorized error when tried to publish pact via gradle

komeershettyvinod
2020-04-30 12:20
Please correct me if I am missing there

komeershettyvinod
2020-04-30 12:20
I just put the login credentials of pact broker url

komeershettyvinod
2020-04-30 12:20
is that right?

komeershettyvinod
2020-04-30 12:33
@asher.feil I was also facing same issue, as part of a POC i am trying to publish a simple pact file via gradle , But i am seeing un uthorization issue. Did you got any soln

komeershettyvinod
2020-04-30 14:22
@matt.fellows Can you please help me here

matt.fellows
2020-04-30 22:08
You need to use tokens and not your username/password

matt.fellows
2020-04-30 22:08
Did you enable the debug logs? You would see a message explaining that

matt.fellows
2020-04-30 22:09
Also the email you received from signup mentions you need a token


uglyog
2020-04-30 23:04
@komeershettyvinod you need to use an API token, not your username and password. You can get an API token from the settings screen in Pactflow.

srinivasan.sekar1990
2020-05-03 10:44
has joined #pact-jvm

srinivasan.sekar1990
2020-05-03 10:48
Hi Team, can someone help me fix below issue when validating messages at producer end of a spring boot kafka application? ```Verifying a pact between dateConsumerKafka and dateProviderKafka [from Pact Broker http://localhost:82/pacts/provider/dateProviderKafka/consumer/dateConsumerKafka/version/0.0.1-SNAPSHOT] valid date from kafka provider Verification Failed - No annotated methods were found for interaction 'valid date from kafka provider'. You need to provide a method annotated with @PactVerifyProvider("valid date from kafka provider") on the classpath that returns the message contents. java.lang.RuntimeException: No annotated methods were found for interaction 'valid date from kafka provider'. You need to provide a method annotated with @PactVerifyProvider("valid date from kafka provider") on the classpath that returns the message contents. at http://au.com.dius.pact.provider.ProviderVerifier.verifyResponseByInvokingProviderMethods(ProviderVerifier.kt:282)``` My provider test looks like below: ```@RunWith(SpringMessagePactRunner.class) @Provider("dateProviderKafka") @Consumer("dateConsumerKafka") @PactBroker(host = "localhost", port = "82") @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class DateProducerTest { @TestTarget public final Target target = new SpringAwareAmqpTarget(); @PactVerifyProvider("valid date from kafka provider") String verifyDateInformationMessage() { System.out.println("i m invoked"); return "{\"isLeapYear\":true,\"localDate\":\"2000-01-31\"}"; } }``` Maven config looks like below: ``` <plugin> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>4.0.0</version> <configuration> <serviceProviders> <serviceProvider> <name>dateProviderKafka</name> <verificationType>ANNOTATED_METHOD</verificationType> <packagesToScan> <packageToScan>http://src.test.java.com.example.producer.pact</packageToScan> </packagesToScan> <pactBroker> <url>http://localhost:82/</url> </pactBroker> </serviceProvider> </serviceProviders> <configuration> <pact.showStacktrace>true</pact.showStacktrace> <pact.verifier.publishResults>true</pact.verifier.publishResults> </configuration> <pactBrokerUrl/> </configuration> </plugin>``` Appreciate any help. Thanks in advance.


chandanakurumeti27
2020-05-04 08:45
Hi , I wanted to use `pact-jvm-consumer` dependency to support (testNG @Test annotation )and not `pact-jvm-consumer-junit.2.11` as my consumer code base is using testNG framework. Is there any possibility to use `pact -jvm-comsumer` dependency which can support TestNG. Cannot really use `pact-jvm-consumer-junit.2.11` for my consumer code base, please help me to find the solution here in this case. looking forward to some suggestions. Thanks, Chandana

chandanakurumeti27
2020-05-04 09:08
Can you please change this line to `@PactFolder("src/test/resources/pacts")` to `@PactFolder("pacts")` as @pactfolder will try to look for the *pacts* inside the *src/test/Resources* by default. From your `@PactFolder("src/test/resources/pacts")` , I guess it is trying to look for `src/test/resources/pacts inside src/test/resources`

chandanakurumeti27
2020-05-04 13:40
Can someone please help me to understand the difference between `pact-jvm-consumer` and `pact-jvm-consumer-junit` dependencies ?

theuiser
2020-05-04 16:52
has joined #pact-jvm

theuiser
2020-05-04 16:54
Hi. I'm want to run my Pact Provider test via mvn. I followed the instructions here: https://github.com/DiUS/pact-jvm/tree/master/provider/pact-jvm-provider-junit and included ```<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> <configuration> <useSystemClassLoader>false</useSystemClassLoader> </configuration> </plugin>``` However, when I run `mvn clean install` it doesn't seem to be running my Pact test (I forced it to fail) because everything still passes.

srinivasan.sekar1990
2020-05-04 17:06
@uglyog Thanks for your time. Unfortunately no luck with above luck. I'm still getting same issue. ```Verifying a pact between dateConsumerKafka and dateProviderKafka [from Pact Broker http://localhost:82/pacts/provider/dateProviderKafka/consumer/dateConsumerKafka/version/0.0.1-SNAPSHOT] valid date from kafka provider Verification Failed - No annotated methods were found for interaction 'valid date from kafka provider'. You need to provide a method annotated with @PactVerifyProvider("valid date from kafka provider") on the classpath that returns the message contents. java.lang.RuntimeException: No annotated methods were found for interaction 'valid date from kafka provider'. You need to provide a method annotated with @PactVerifyProvider("valid date from kafka provider") on the classpath that returns the message contents. ```

wesleythomaswilliams
2020-05-04 20:24
Hi Tanya, have you included these dependencies: ``` <dependency> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-junit5</artifactId> <version>${pact.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>${pact.version}</version> <scope>test</scope> </dependency>```

wesleythomaswilliams
2020-05-04 20:25
Also, are you junit4 or junit5?

theuiser
2020-05-04 20:52
@wesleythomaswilliams I'm using junit5. I have the following ```<dependency> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-junit5_2.12</artifactId> <version>${pact.version}</version> <scope>test</scope> </dependency>```

theuiser
2020-05-04 20:53
I was able to get it working after following instructions from this article: https://blog.ramjee.uk/microservices-and-consumer-tests/

theuiser
2020-05-04 20:55
My setup: ``` <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> <dependencies> <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-surefire-provider</artifactId> <version>1.2.0</version> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.2.0</version> </dependency> </dependencies> </plugin>```

wesleythomaswilliams
2020-05-04 20:56
Glad you've got it working :slightly_smiling_face:

theuiser
2020-05-04 20:56
Wondering if that should be included in the Pact docs: https://github.com/DiUS/pact-jvm/tree/master/provider/pact-jvm-provider-junit @uglyog

theuiser
2020-05-04 20:57
The next step is to publish the verification results. @wesleythomaswilliams Have you done that by any chance?

wesleythomaswilliams
2020-05-04 21:53
I have

wesleythomaswilliams
2020-05-04 21:55
I restrict publishing of verification results to our pipeline only. I decided I don't want that to happen in local builds unless it's deemed absolutely necessary, so I set these defaults in our pom ``` <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <systemPropertyVariables> <pact.broker.host>http://mybroker.pact.dius.com.au</pact.broker.host> <pact.broker.token>mytoken</pact.broker.token> <pact.verifier.publishResults>false</pact.verifier.publishResults> <pact.provider.version>${pact.provider.version}</pact.provider.version> <pact.provider.version.trimSnapshot>false</pact.provider.version.trimSnapshot> </systemPropertyVariables> </configuration> </plugin>```

wesleythomaswilliams
2020-05-04 21:57
In my pipeline when I execute provider tests, I have something like this: ``` ' mvn -B -f pom.xml verify' + ' -Dpact.provider.version=' + env.GIT_COMMIT + ' -Dpact.verifier.publishResults=true' + ' -Dpact.provider.tag=' + env.GIT_BRANCH```

theuiser
2020-05-04 22:02
I believe it?s this plugin that lets me run pact:verify, right? ``` <dependency> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>${pact.version}</version> <scope>test</scope> </dependency>```

uglyog
2020-05-04 23:08
I'm just trying to work out what you're actually asking. I think you want to use TestNG instead of JUnit? If that is the case, there is no direct support for TestNG. You can use the `pact-jvm-consumer` to write your own TestNG support.

abubics
2020-05-04 23:51
The distinction is hinted at in https://github.com/DiUS/pact-jvm#service-consumers: > *Service Consumers* > Pact-JVM has a number of ways you can write your service consumer tests. > > *I Use Scala* > You want to look at: https://github.com/ITV/scala-pact or https://github.com/DiUS/pact-jvm/blob/master/consumer/pact-jvm-consumer-specs2 > > *I Use Java* > You want to look at: https://github.com/DiUS/pact-jvm/blob/master/consumer/pact-jvm-consumer-junit for JUnit 4 tests and https://github.com/DiUS/pact-jvm/blob/master/consumer/pact-jvm-consumer-junit5 for JUnit 5 tests. Also, if you are using Java 8, there is https://github.com/DiUS/pact-jvm/blob/master/consumer/pact-jvm-consumer-java8. > > ... > > *I Use some other jvm language or test framework* > You want to look at: https://github.com/DiUS/pact-jvm/blob/master/consumer/pact-jvm-consumer

abubics
2020-05-04 23:52
but, basically, `pact-jvm-consumer` is the base library, and `pact-jvm-consumer-junit` is junit bindings for the base

wesleythomaswilliams
2020-05-05 08:28
Yes, I believe so

wesleythomaswilliams
2020-05-05 08:28
I have both of these defined in my provider pom ``` <dependency> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-junit5</artifactId> <version>${pact.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>http://au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>${pact.version}</version> <scope>test</scope> </dependency>```

chandanakurumeti27
2020-05-05 09:43
Is there any example to consider for reference where i can use `pact-jvm-consumer` to write my own TestNG support ? if so please provide the link.Thank you

rjaladurgam
2020-05-05 16:42
has joined #pact-jvm


nick.smith3128
2020-05-06 14:21
has joined #pact-jvm

nick.smith3128
2020-05-06 14:22
hi. is there any reason why my Pact file generation fails unless I put a sleep in @PactVerificationmethopd? ```@Test @PactVerification(fragment = "createCreateAssetSyndicationResponse") public void doCreateCreateAssetSyndicationResponse() throws InterruptedException { Thread.sleep(WAIT_TIME); new CustomClient().getPostResponse(ENTERPRISE_API_PATH + GET_ASSETS + "/" + ROOT_MEDIA_ASSET + ASSET_SYNDICATION_API); }``` If I dont have it then i get the error: ```[ERROR] EnterpriseCreateAssetSyndicationConsumerTest.doCreateCreateAssetSyndicationResponse Pact Test function failed with an exception, possibly due to ExpectedButNotReceived(expectedRequests=[ method: POST path: /api/assets/70/syndication query: {} headers: {} matchers: MatchingRules(rules={path=Category(name=path, matchingRules={=MatchingRuleGroup(rules=[RegexMatcher(regex=/api/assets/[0-9]+/syndication, example=null)], ruleLogic=AND)})}) generators: Generators(categories={}) body: MISSING]) [INFO] ``` I'm using v4.0.10

nick.smith3128
2020-05-06 14:54
ok looks like this was the issue https://github.com/DiUS/pact-jvm/issues/342

plessmann
2020-05-07 13:09
has joined #pact-jvm

plessmann
2020-05-07 13:10
Hi all, Im following https://github.com/DiUS/pact-jvm/blob/v4.x/consumer/pact-jvm-consumer-specs2/src/test/scala/au/com/dius/pact/consumer/specs2/ExamplePactSpec.scala to migrate from ScalaPact to PactJVM. Im having an issue when having 2 interactions like in the example, i get the following exception: ```[error] java.lang.UnsupportedOperationException: null (MutableCollectionsJVM.kt:42) [error] kotlin.collections.CollectionsKt__MutableCollectionsJVMKt.sortWith(MutableCollectionsJVM.kt:42) [error] http://au.com.dius.pact.core.model.RequestResponsePact.sortInteractions(RequestResponsePact.kt:65) [error] http://au.com.dius.pact.core.model.DefaultPactWriter.writePact(PactWriter.kt:56) [error] http://au.com.dius.pact.core.model.DefaultPactWriter.writePact(PactWriter.kt:100) [error] http://au.com.dius.pact.consumer.BaseMockServer.verifyResultAndWritePact(MockHttpServer.kt:133) [error] http://au.com.dius.pact.consumer.BaseMockServer.runAndWritePact(MockHttpServer.kt:119) [error] http://au.com.dius.pact.consumer.ConsumerPactRunnerKt.runConsumerTest(ConsumerPactRunner.kt:13) [error] http://au.com.dius.pact.consumer.specs2.PactSpec$ReadyForTest.$anonfun$withConsumerTest$2(PactSpec.scala:54) [error] http://au.com.dius.pact.consumer.specs2.PactSpec$$anon$1.asResult(PactSpec.scala:33)``` I copied the example from the repo previously referenced and got the same error. So far i can infer an issue while sorting interactions but i have no clue what i am missing, can anyone point me in the correct path? Im using Java 11 but it also fails in Java 8.

antonello
2020-05-07 18:47
Our team has come across and raised this issue today https://github.com/DiUS/pact-jvm/issues/1086 Is there something we?re missing?

uglyog
2020-05-07 22:55
Can you raise an issue on Github? TBH, the Scala support hasn't been looked at for a long time because Scala-Pact existed. Is there a reason you are trying to migrate to Pact-JVM?

abubics
2020-05-07 23:44
Probably because ScalaPact is kinda nonstandard and unsupported :stuck_out_tongue:

plessmann
2020-05-08 07:04
my organization is mostly Java prefering PactJVM because of Pact V3, so in oder to standarize we started this migration

plessmann
2020-05-08 07:05
ok, i will create an issue

plessmann
2020-05-08 08:23
i created it https://github.com/DiUS/pact-jvm/issues/1088 thanks for your help :slightly_smiling_face:

hoagiex
2020-05-09 21:53
has joined #pact-jvm

hoagiex
2020-05-09 21:53
nvm, found it: I needed a generator in the json

preethighalke
2020-05-11 04:26
Thank you @chandanakurumeti27 !!

hans.brouwer
2020-05-13 08:27
has joined #pact-jvm

hans.brouwer
2020-05-13 08:59
Hi, we are using Scala 2.13 and want to do CDC-testing with kafka. Which version of the pact-jvm should we use?

uglyog
2020-05-13 23:14
Depends on the version of Java you want to use. I don't think the Spec2 and Scalatest support is working with the latest version (I haven't checked it), but if you stick to JUnit tests it should work.

ashwin.bakker
2020-05-14 12:22
has joined #pact-jvm

ashwin.bakker
2020-05-14 13:36
Hi Pact community! Question: I'm trying to add an authorization token to the request headers in my provider verification tests using `@TargetRequestFilter`, but I'm getting the exception `java.lang.Exception: Method addJwtToHeaderFilter should take only a single HttpRequest parameter`. I've tried changing `HttpRequest` to `MockHttpServletRequestBuilder` as per https://github.com/DiUS/pact-jvm/issues/983 but to no avail. Has something changed in the way headers should be added to requests? This is the test: ```@RunWith(SpringRestPactRunner.class) @ActiveProfiles("default") @Provider("RekeningInzicht") @PactBroker(scheme = "https", host = "MY_PACTFLOW", port = "443", authentication = @PactBrokerAuth(token = "MY_TOKEN")) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class MijnRekeningRekeningInzichtSpringPactRunner extends BaseOperationIntegrationTest { @TestTarget public final Target target = new SpringBootHttpTarget(); @MockBean private RekeningenService rekeningenService; @BeforeClass public static void setupOnce() { System.setProperty("developmentMode", "true"); } @Before public void setup() { IntegrationTestHelper.createTokenForContract( authenticator, IdentityType.CUSTOMER, AuthLevel.LEVEL30, ConfLevel.PUBLIC, IntegrationTestHelper.DEFAULT_CONTRACT); } @TargetRequestFilter public void addJwtToHeaderFilter(HttpRequest request) { request.getHeaders().add(IntegrationTestHelper.customerHeader.getName(), IntegrationTestHelper.customerHeader.getValue()); } @State("logged in user") public void getRekening() { reset(rekeningenService); } }``` Brief explanation: the class extends a base class `BaseOperationIntegrationTest` used by all integration tests my organization writes. I'm not sure if it's relevant, but I'll share it anyways: ```@RunWith(SpringRunner.class) @SpringBootTest @ActiveProfiles({"integration"}) public abstract class BaseOperationIntegrationTest { protected MockMvc mockMvc; @Autowired protected WebApplicationContext webApplicationContext; @Autowired protected MockIdentityAuthenticator authenticator; @Autowired protected List<FilterRegistrationBean> filterRegistrationBeans; @Autowired private FilterChainProxy filterChainProxy; public BaseOperationIntegrationTest() { } @Before public final void beforeBaseOperationIntegrationTest() { this.initializeMockMvc(); } protected void initializeMockMvc() { Filter[] filters = (Filter[])this.filterRegistrationBeans.stream().map(FilterRegistrationBean::getFilter).filter((f) -> { return f.getClass().getSimpleName().matches(".*(Logging|HeaderContext)Filter"); }).toArray((x$0) -> { return new Filter[x$0]; }); this.mockMvc = ((DefaultMockMvcBuilder)((DefaultMockMvcBuilder)MockMvcBuilders.webAppContextSetup(this.webApplicationContext).addFilters(filters)).addFilter(this.filterChainProxy, new String[0])).build(); } }``` Full exxception: java.lang.Exception: Method addJwtToHeaderFilter should take only a single HttpRequest parameter at au.com.dius.pact.provider.junit.target.BaseTarget.validateTargetRequestFilters(BaseTarget.kt:111) at au.com.dius.pact.provider.junit.target.HttpTarget.getProviderInfo(HttpTarget.kt:121) at au.com.dius.pact.provider.junit.target.HttpTarget.testInteraction(HttpTarget.kt:67) at http://au.com.dius.pact.provider.junit.InteractionRunner$interactionBlock$statement$1.evaluate(InteractionRunner.kt:204) at http://au.com.dius.pact.provider.junit.RunStateChanges.evaluate(RunStateChanges.kt:20) at http://au.com.dius.pact.provider.spring.SpringBeforeRunner.evaluate(SpringInteractionRunner.kt:32) at http://au.com.dius.pact.provider.spring.SpringAfterRunner.evaluate(SpringInteractionRunner.kt:48) at au.com.dius.pact.provider.junit.InteractionRunner.run(InteractionRunner.kt:145) at http://au.com.dius.pact.provider.junit.PactRunner.runChild(PactRunner.kt:147) at http://au.com.dius.pact.provider.junit.PactRunner.runChild(PactRunner.kt:52) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:64) The way tokens are generated is copied from their existing integration tests. Usage of tokens is mandatory and cannot be disabled. Me and my team are trying to introduce CDCT using Pact to the development teams at one of the larger banks here in The Netherlands, so we want to make adoption as easy as possible for them. That's why I'm closely following the way they currently run integration tests. I'm having some trouble determining what goes wrong when the `@TargetRequestFilter` is called, since evidently more than one parameter is passed to the function. Can anyone provide us with some insights? Thanks! EDIT: we use `pact-jvm-provider-spring` version `4.0.10`

mbieganski.infomatt
2020-05-14 14:11
Hi is there a plan to add this functionality https://github.com/DiUS/pact-jvm/issues/600 in any nearest release?

uglyog
2020-05-15 00:15
Can you confirm the import for the HttpRequest you are using? Is it `org.apache.http.HttpRequest`?

uglyog
2020-05-15 00:17
I've recently implemented this in the Pact-Rust, Pact-JS V3 and Pact-C++. I can now port that back to the JVM version.

ashwin.bakker
2020-05-15 07:23
@uglyog My goodness, I can't believe I used a wrong import :rolling_on_the_floor_laughing::rolling_on_the_floor_laughing: I was using `org.springframework.http.HttpRequest` . I was in such a Spring mindset that I just automatically imported that one as soon as I saw 'spring'. The header is now added, thank you!! :smile:

antonello
2020-05-18 09:29
For anyone who is/was interested in this issue: https://github.com/DiUS/pact-jvm/issues/1035, we?re putting it to bed by migrating provider tests to Junit5. The filtering using `@Tag` prevents the spring context to be initialised even when no tests are running. (use case is that we don?t run provider verification with all other tests, but in a separate stage).

robert.strauch_slack
2020-05-18 21:25
has joined #pact-jvm

robert.strauch_slack
2020-05-18 21:30
Taking my first steps with pact-jvm. I do have a pact file and would now like to verify the provider. I took the JUnit5 approach. ```@Provider("my-backend") @PactFolder("src/test/resources/pacts") public class PactProviderTest { private static final String PROVIDER_URL = "http://localhost:8090"; @BeforeEach void before(PactVerificationContext context) throws MalformedURLException { context.setTarget(HttpTestTarget.fromUrl(new URL(PROVIDER_URL))); } @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) private void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); } }``` When running this test class I get the message that no tests were found. Using the same directory with the Maven plugin executes just fine. Is there something I'm missing?

wesleythomaswilliams
2020-05-18 21:36
You'll want @state methods to validate the pact against.

wesleythomaswilliams
2020-05-18 21:38
JUnit 5?s @TestTemplate feature is used in combination with PactVerificationInvocationContextProvider to dynamically create a test for every interaction found in the pact. For REST contracts, verifyInteraction is executed against methods with the @State annotation. For Messaging contracts, the @PactVerifyProvider annotation is used.

wesleythomaswilliams
2020-05-18 21:41
The value of the @state annotation should match the .given value set in the consumer test.

robert.strauch_slack
2020-05-18 21:44
Ah, I see... thanks. My understanding was that `@State` was only necessary when not using the test template. Guess I was wrong :-)

robert.strauch_slack
2020-05-18 22:01
Hmmm, guess I'm still missing something. I added the following to the class: ```@State("portal API is deployed") public void check() { System.out.println("foo"); }``` The interaction reads: `"providerState": "portal API is deployed"` but it stil says that no tests are found.

robert.strauch_slack
2020-05-18 22:17
Found the mistake... I marked the before and template methods as private. Having removed this is working

baquinteros
2020-05-19 12:53
Hey there, I'm a noob to java and pact jvm. I'm using the junit5 consumer like https://github.com/DiUS/pact-jvm/blob/master/consumer/pact-jvm-consumer-junit5/src/test/java/au/com/dius/pact/consumer/junit5/ArticlesTest.java And I'm trying to set the ProviderInfo to https and insecure which looks like it's a param for https://github.com/DiUS/pact-jvm/blob/fc25baf610dd78c2c9b4ff95a29a4a92d42a5212/consumer/pact-jvm-consumer-junit5/src/main/kotlin/au/com/dius/pact/consumer/junit5/PactConsumerTestExt.kt#L189 so the test hits a https mockServer. How can I achieve this?

wesleythomaswilliams
2020-05-19 13:51
I don't suppose anyone is aware of a convertor that reads a piece of json and turns it into PactDslJsonBody. That would make my life so much easier. :smile: Also, does everyone else write their PactDslJsonBody with indentation to match the indentation in their json? I find it's the only way I can make it readable, but my IDE just wants it all in a flat structure. e.g.: I write: ```final DslPart body = new PactDslJsonBody() .object("idWrapper") .stringType("sain", "9rz8rz2y") .eachLike("identifiers", 1) .stringType("alias", "thing") .minArrayLike("value", 1, PactDslJsonRootValue.stringType("0634158430268"), 1) .closeObject() .closeArray().asBody() .minArrayLike("aliases", 1, PactDslJsonRootValue.stringType("Test"), 1) .closeObject()``` My IDE would prefer it if I wrote: ```final DslPart body = new PactDslJsonBody() .object("idWrapper") .stringType("sain", "9rz8rz2y") .eachLike("identifiers", 1) .stringType("alias", "thing") .minArrayLike("value", 1, PactDslJsonRootValue.stringType("0634158430268"), 1) .closeObject() .closeArray().asBody() .minArrayLike("aliases", 1, PactDslJsonRootValue.stringType("Test"), 1) .closeObject()``` So any time I cut and paste what I've written into a another class, it automatically flattens it :disappointed:

uglyog
2020-05-19 22:47
Pact JUnit 5 has no may to specificity to use a HTTPS mock server. Please raise an issue for this at the github project.

matt.fellows
2020-05-19 22:58
Oh, a client I worked on did this

matt.fellows
2020-05-19 22:58
I?ll see if they are willing to share it

matt.fellows
2020-05-19 22:58
they created an Intellij plugin actually


antonello
2020-05-20 06:18
Support for pending pacts in 4.1.0! ?

wesleythomaswilliams
2020-05-20 08:12
And I'm using IntelliJ, so that would be great.

matt.fellows
2020-05-20 10:06
I?ll ping them now

thinh.tranquoc
2020-05-20 10:57
has joined #pact-jvm

ashish_garg5
2020-05-20 11:08
has joined #pact-jvm

thinh.tranquoc
2020-05-20 11:08
hi all, I have a question https://stackoverflow.com/questions/61206271/pact-jvm-matching-rules-are-being-ignored-when-running-test . Could you please help me a response :slightly_smiling_face:

ashish_garg5
2020-05-20 11:08
Hi All, I want to combine my GET and POST request. return builder .given("create inventory").uponReceiving("a request to save inventory").path("/api/inventory") .body(requestBody).method(RequestMethod.POST.name()).willRespondWith().headers(headers).status(200) .body(responseBody) .toPact(); return builder .given("get inventory").uponReceiving("a request to get inventory").path("/api/inventory").method("GET") .willRespondWith().headers(headers).status(200).body(responseBody) .toPact(); right now i have these 2 in different files if i am combining i am getting error. Please help.

matt.fellows
2020-05-20 11:09
Ashish, it looks like you?re trying to first ?create? the inventory and then ?get? it. That smells like a typical end-to-end test, which is not how you should approach things in Pact

matt.fellows
2020-05-20 11:10
You should instead use a state for the GET call. e.g. ?inventory with id X exists?

ashish_garg5
2020-05-20 11:14
sorry i didn't get actually... i am new to pact so i just wanted to combine 2 api's in same builder instead of creating a different class for it

matt.fellows
2020-05-20 11:15
Why do you need to create it in the same builder though?

matt.fellows
2020-05-20 11:15
As a general rule, you want each interaction to have its own test


wesleythomaswilliams
2020-05-20 11:21
@ashish_garg5 This previous thread may be of help: https://pact-foundation.slack.com/archives/C5F4KFKR8/p1588616560319700

wesleythomaswilliams
2020-05-20 11:22
I think from your example, you have one API, but you want to make different types of call to that API (e.g. GET, POST etc.).

matt.fellows
2020-05-20 11:55
Wes, are you a bot?!

wesleythomaswilliams
2020-05-20 12:01
lol, just a guy who gets far too easily distracted and uses slack waaay too much

jake.chandrasakera
2020-05-20 12:28
has joined #pact-jvm

sairsule
2020-05-20 13:22
has joined #pact-jvm

sairsule
2020-05-20 13:39
what version of JDK is recommended to work with Pact?

sairsule
2020-05-20 13:58
i am getting following error while trying out workshop project org.gradle.api.GradleScriptException: A problem occurred evaluating project ':providers:dropwizard-provider'.

aliihlail
2020-05-21 13:46
Hi i wrote a test for provider service. when i run the code locally every thing works fine. once i upload it bitbucket i got the followin error Failed to invoke provider method 'testDocumentService2' (java.lang.RuntimeException)

lankala321
2020-05-21 13:48
has joined #pact-jvm

aliihlail
2020-05-21 14:18
`Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.logging.log4j.util.PropertiesUtil at org.apache.logging.log4j.status.StatusLogger.<clinit>(StatusLogger.java:71) at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:60) at org.apache.commons.logging.LogFactory$Log4jLog.<clinit>(LogFactory.java:199) at org.apache.commons.logging.LogFactory$Log4jDelegate.createLog(LogFactory.java:166) at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:109) at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:99) at org.springframework.beans.BeanUtils.<clinit>(BeanUtils.java:68) at de.mediciliving.cloud.contact.member.QuartersMemberMapper.toMessageModel(QuartersMemberMapper.java:43) at de.mediciliving.cloud.contact.member.QuartersMemberMapper.createMessageModel(QuartersMemberMapper.java:71) at de.mediciliving.cloud.contact.pactTesting.CommunityAmqpVerificationTest.testCommunityServiceMemberProfileIsCreated(CommunityAmqpVerificationTest.java:61)`

aliihlail
2020-05-21 14:18
here is the error also which i got in bitbucket

praneethkumar
2020-05-21 15:57
has joined #pact-jvm

antonello
2020-05-22 07:13
Can @PactUrl point to a specific url in the broker or can it only be to a file system? https://github.com/DiUS/pact-jvm/blob/master/provider/junit/README.md#pact-url

uglyog
2020-05-22 07:14
Any URL

antonello
2020-05-22 07:27
Great - so I think this should help with the issue I mentioned earlier.

uglyog
2020-05-22 07:40
The only problem is that @PactUrl won't include the bearer token (if the broker is authenticated)

antonello
2020-05-22 07:43
Luckily it isn?t :)

aliihlail
2020-05-22 09:24
I have an issue: trying to i worte an Amqp test but when we have more than one amq contract at the proider side i got the following error at pact Broker Failed to invoke provider method 'testCommunityServiceMemberProfileIsCreated' (java.lang.RuntimeException) also i got an error `aused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.logging.log4j.util.PropertiesUtil`

wesleythomaswilliams
2020-05-22 10:02
Can you share the whole provider test class

praneethkumar
2020-05-22 10:21
I am getting the below error when running the. Provider test against a real API . ?Expected a response type of 'application/json' but the actual type was 'text/plain'?. The API is returning Json Did anyone face this issue ?

aliihlail
2020-05-22 10:22
``` @ExtendWith(PactConsumerTestExt.class) @PactTestFor(providerName = "contact-service", providerType = ProviderType.ASYNCH) public class ContactAmqpTest { @Pact(consumer = "document-service") public MessagePact createCustomerDocumentsPact(MessagePactBuilder builder) { return builder .given("member document is created") .expectsToReceive("CONTACT_SERVICE_MEMBER_CREATED") .withContent(newJsonBody((result) -> { result.object("entities", (entities) -> { entities.object("member", (member) -> { member.id("id"); member.stringType("firstName"); member.stringType("lastName"); member.datetimeExpression("createdAt", "2020-01-01T12:20:40"); member.stringMatcher("countryCode", "DE|NL|US", "DE"); }); }); }).getPactDslObject()) .toPact(); } @Pact(consumer = "document-service") public MessagePact reCreateCustomerDocumentsPact(MessagePactBuilder builder) { return builder .given("member document is recreated") .expectsToReceive("CONTACT_SERVICE_MEMBER_RECREATE_DOCUMENTS") .withContent(newJsonBody((result) -> { result.object("entities", (entities) -> { entities.object("member", (member) -> { member.id("id"); member.stringType("firstName"); member.stringType("lastName"); member.datetimeExpression("createdAt", "2020-01-01T12:20:40"); member.stringMatcher("countryCode", "DE|NL|US", "DE"); }); }); }).getPactDslObject()) .toPact(); } @Test @PactTestFor(pactMethod = "createCustomerDocumentsPact") void testCreateContactDocumentPact(List<Message> messages) { } @Test @PactTestFor(pactMethod = "reCreateCustomerDocumentsPact") void testReCreateContactDocumentPact(List<Message> messages) { } }```

aliihlail
2020-05-22 10:24
```package de.mediciliving.cloud.community.pact.pactConsumer; import http://au.com.dius.pact.consumer.MessagePactBuilder; import http://au.com.dius.pact.consumer.junit5.PactConsumerTestExt; import http://au.com.dius.pact.consumer.junit5.PactTestFor; import http://au.com.dius.pact.consumer.junit5.ProviderType; import http://au.com.dius.pact.core.model.annotations.Pact; import http://au.com.dius.pact.core.model.messaging.Message; import http://au.com.dius.pact.core.model.messaging.MessagePact; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import java.util.List; import static io.pactfoundation.consumer.dsl.LambdaDsl.newJsonBody; @ExtendWith(PactConsumerTestExt.class) @PactTestFor(providerName = "contact-service", providerType = ProviderType.ASYNCH) public class ContactAmqpTest { @Pact(consumer = "community-service") public MessagePact createChatProfilePact(MessagePactBuilder builder) { return builder .given("member profile is created") .expectsToReceive("CONTACT_SERVICE_MEMBER_CREATED") .withContent(newJsonBody((result) -> { result.object("entities", (entities) -> { entities.object("member", (member) -> { member.numberType("userId"); member.stringType("firstName"); member.stringType("lastName"); }); }); }).getPactDslObject()) .toPact(); } @Pact(consumer = "community-service") public MessagePact deleteProfilePact(MessagePactBuilder builder) { return builder .given("member profile is disabled") .expectsToReceive("CONTACT_SERVICE_MEMBER_STATUS_DISABLED") .withContent(newJsonBody((result) -> { result.object("entities", (entities) -> { entities.object("member", (member) -> { member.numberType("userId"); }); }); }).getPactDslObject()) .toPact(); } @Test @PactTestFor(pactMethod = "createChatProfilePact") void testCreateChatProfilePact(List<Message> messages) { } @Test @PactTestFor(pactMethod = "deleteProfilePact") void testDeleteProfilePact(List<Message> messages) { } }```

matt.fellows
2020-05-22 10:25
Check Content type header

praneethkumar
2020-05-22 10:33
Hi Matt , the expected content type was application/ json and the api is returning the same . But for some reason the test fails

matt.fellows
2020-05-22 10:53
Can you please show some logs to prove that? I'm 99.99% sure that your provider is not returning the correct header

matt.fellows
2020-05-22 10:54
Alternatively it's hitting the wrong endpoint which doesn't send that header

sairsule
2020-05-22 12:19
JVM workshop project does not compile. Is anybody else facing the issue?

sairsule
2020-05-22 12:19
Could not resolve all files for configuration ':providers:dropwizard-provider:compile'. > Could not resolve org.slf4j:slf4j-api:1.7.22. Required by: project :providers:dropwizard-provider > Could not resolve org.slf4j:slf4j-api:1.7.22. > Could not get resource 'https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.22/slf4j-api-1.7.22.pom'. > Could not HEAD 'https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.22/slf4j-api-1.7.22.pom'. > Received fatal alert: protocol_version

sairsule
2020-05-22 14:47
Nevermind, got to know this is my JDK error

zeldigas
2020-05-22 17:49
has joined #pact-jvm

uglyog
2020-05-24 00:20
This looks like an issue with your project. You might be missing a library your code is using.

uglyog
2020-05-24 00:21
`org.apache.logging.log4j.util.PropertiesUtil` is not used by anything the Pact-JVM libraries.

mbieganski.infomatt
2020-05-25 09:03
Hi. I'm working now the amqp contract tests. Could you tell me what is the difference between @PactVerifyProvider and @State annotations? From what I have read it seems to be the same where @State is being used in Rest. Unless I'm missing something. Thanks!

wesleythomaswilliams
2020-05-25 14:40


mbieganski.infomatt
2020-05-25 20:25
Thanks @wesleythomaswilliams! `given` and `expectsToReceive` messed with me.. Messages are giving me a bit of a headache :wink: @uglyog can I in `@PactVerifyProvier` return whole message and the metadata will be verified as well?

uglyog
2020-05-25 22:59
Yes, if you return both, they will both be verified

ashish_garg5
2020-05-26 05:44
Hi All, How can i pass a json body in my PactDslJsonBody response ? I have created a json file which my consumer is expecting as a response now i want to pass that in my PactDslJsonBody response. // Want to do something like this PactDslJsonBody responseBody = new PactDslJsonBody().object("test.json");

uglyog
2020-05-26 05:50
If you load the file into a String, you can then use `PactDslResponse.body(String body, String contentType)`

ashish_garg5
2020-05-26 05:52
so how can i load the file in String, do i have to hard code the json file content so there is a way to directly load it ?

uglyog
2020-05-26 05:54
Are you using Java, or some other language?

ashish_garg5
2020-05-26 05:54
Java

uglyog
2020-05-26 05:55
Do you any libraries like Apache commons-io?


ashish_garg5
2020-05-26 05:58
ok so there is no way so that i can directly read in PactDslJsonBody, 1st i have to write a code to read it from file and then i can use that.

uglyog
2020-05-26 05:59
Oh, you're asking to construct a PactDslJsonBody object from the contents of a JSON file. I think someone may have created a library to do that, but I don't know about it

ashish_garg5
2020-05-26 06:00
yeah correct i am asking to contruct a PactDslJsonBody, ok thanks.

ashish_garg5
2020-05-26 08:13
Hi, How can i pass Map<String, Object> in my PactDslJsonBody while constructing ?

ashish_garg5
2020-05-26 10:51
Hi All, How i can pass parameter in my api call ? return builder.path("api/test")... now here i want to pass a parameter api/test?param="paramValue"

matt.fellows
2020-05-26 12:02
What have you tried? What docs have you looked at?

francislainy.campos
2020-05-26 16:05
has joined #pact-jvm

francislainy.campos
2020-05-26 16:05
Hi, How do I check for longs as in `"timestamp": 1589451234126` in PACT with Java, since integer or number type is not available for large numbers please?

wesleythomaswilliams
2020-05-26 16:08
I assume you can't match with ```.numberType("timestamp", 1589451234126)```

francislainy.campos
2020-05-26 16:09
Hi, no, that gives me an error due to the length of the input.

francislainy.campos
2020-05-26 16:18
Removed the sample for the input altogether such as in `.integerType("timestamp")` rather than `.integerType("timestamp", 1589451234126)` and it worked now. Thanks.

francislainy.campos
2020-05-26 16:24
Hi, different issue. Could I get some help with this error I'm getting here please? https://stackoverflow.com/questions/62001663/exception-in-thread-thread-2-java-lang-nosuchmethoderror-kotlin-io-bytestream. Thank you very much.

ashish_garg5
2020-05-27 04:57
Hi All, How can i publish provider tag in pact broker ? <systemPropertyVariables> <pact.provider.version>${version}</pact.provider.version> <pact.provider.tag>dev</pact.provider.tag> <pact.verifier.publishResults>true</pact.verifier.publishResults> </systemPropertyVariables> I am able to publish version and results by configure it in system props but tag is not getting published.

uglyog
2020-05-27 05:01
`pact.provider.tag` is the correct system property. How are you determining that it is not being published with the results?

ashish_garg5
2020-05-27 05:03
m not able to see tag name in pact broker

ashish_garg5
2020-05-27 05:03
and if m using can i deploy its not able to find tag for provider

uglyog
2020-05-27 05:06
What version of the Pact Broker do you have?

ashish_garg5
2020-05-27 05:06
can-i-deploy?pacticipant=PactConsumerJavaRest&version=1.0.0&to=dev this is not working in my pact broker as provider tag is not published can-i-deploy?pacticipant=PactConsumerJavaRest&version=1.0.0 but if i remove the tag and check only

ashish_garg5
2020-05-27 05:06
3.6.7

uglyog
2020-05-27 05:07
Is that Pact-JVM version?

ashish_garg5
2020-05-27 05:09
yes

uglyog
2020-05-27 05:10
Publishing provider tags is implemented in 3.6.15 or 4.0.2+

ashish_garg5
2020-05-27 05:10
ohh k

ashish_garg5
2020-05-27 05:10
so i have to upgrade my version

francislainy.campos
2020-05-27 09:33
Hi, good morning. I'm trying to initiate my base url based on a param given so tried to add a before method to my class but that doesn't seem to work. Any ideas on how to do this please?

zeldigas
2020-05-27 09:53
Hi guys, I'm a bit confused with docs about publishing provider verification results. Context: I'm using junit5 to create provider tests ```@PactBroker(host="http://example.org") @VerificationReports("console", "json") @Provider("my_provider") class TpsCommandsProviderTest { @BeforeEach fun before(context: PactVerificationContext) { context.target = AmpqTestTarget() } @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider::class) fun pactVerificationTestTemplate(context: PactVerificationContext) { context.verifyInteraction() } @PactVerifyProvider("Build message command") fun buildTreamentMessage():String = """{"hello": "world"}""" }```

zeldigas
2020-05-27 09:55
So the question is how to properly publish verification results? Pact maven plugin docs tells me that I need to set `pact.verifier.publishResults` inside pact maven configuration, not in surefire

zeldigas
2020-05-27 09:56
But during regular tests execution I see a warning that results are not published as property is not set

wesleythomaswilliams
2020-05-27 09:56
@zeldigas I had to set it in surefire to get it to work

zeldigas
2020-05-27 09:57
Ok, thanks @wesleythomaswilliams. Looks like docs are confusing or applicable to different use case..



zeldigas
2020-05-27 10:00
Great, thank you for detailed example. I also was about doing the same thing, just wanted to doublecheck if I'm missing something

aliihlail
2020-05-27 10:03
i found an issue when im trying to test service that send the same message to different other service. i used the message event as PactVerifyProvider at the provider side and expectsToReceive at the consumer side. what i found the pact tries to pic all the the same expectsToReceive even if they are in different pact consumers. any idea how to overcome this


aliihlail
2020-05-27 10:03
```@State("Contract is created") @PactVerifyProvider("CONTRACT_SERVICE_CONTRACT_STATUS_CREATED") public JsonNode testContractServiceStatusCreated() { Contract contract = TestContractFactory.createContract(); contract.setRebookedContract(TestContractFactory.createContract()); contract.setStatus(Contract.Status.CREATED); MessageModel model = contractMapper.toMessageModel(contract); JsonNode messageModel = JacksonUtil.toJsonTree(model); return messageModel; }``` here is an example at the provider side

aliihlail
2020-05-27 10:04
unfortunately it fails until i change the PactVerifyProvider

wesleythomaswilliams
2020-05-27 10:08
@aliihlail If it's any use for your case, my messaging tests don't make use of state, just @PactVerifyProvider. My consumer is tagged as: ```@Pact(provider = "provider-service", consumer = "consumer-service")``` and has: ```.expectsToReceive("a provider-service update")``` My provider just has: ```@PactVerifyProvider("a provider-service update")``` I only have one consumer from that provider though.

aliihlail
2020-05-27 10:28
@wesleythomaswilliams i have the same but as i mentioned when there is more than one consumer then it may has a problem

wesleythomaswilliams
2020-05-27 10:32
@aliihlail With my REST tests where I have one provider and multiple consumers, it's the `.given` field in the builder that ties to the `@state` tag. Would adding that solve this?

aliihlail
2020-05-27 10:35
with rest it is not a problem. I think the issue that with Amqp that it tests all contracts who have the same PactVerifyProvider. What i need is to pick the only the PactVerifyProvider for the specific consumer

sairsule
2020-05-27 15:52
~Hi All, are there any examples of message-driven pacts tests in GO?~

antonello
2020-05-27 19:09
We have a provider (a BFF) that is organised in multiple modules, each module is responsible for different areas of the domain and each module has its own controllers. Any recommendations on how to go about organising the provider tests? I can think of two options and I like neither: 1. Each module would have its own test class, but states would need to be filtered. However, using `@PactFilter` to split state change methods is a recipe for disaster as we?ve realised when doing it for other applications, as it leads to verifications passing when they should not. 2. Treat each module as a separate provider with a different name. I don?t like this either as it would quickly lead to a proliferation of providers.

aliihlail
2020-05-27 22:19
Thanks for your recommendation. but i thought since they are in 2 different contracts then this the provider should search only for its related contract from the brocker. i do not see my self is going with both suggestions also the first one does not work.

antonello
2020-05-27 22:22
Ali - not making any recommendations here, asking for advice instead.

uglyog
2020-05-27 23:01
Unfortunately, the target is a field so it will be set when the test class is instantiated. But you can try instantiate the test target in the before method, that might work.

uglyog
2020-05-27 23:03
No, that won't work either. Sorry. The only way is to create a subclass of HttpTarget that can override the host name. Or you can try using JUnit 5.

uglyog
2020-05-27 23:04
If you're using JUnit tests, you are not using the Pact Maven plugin. So just set the property in the Surefire config or on the Maven command line

uglyog
2020-05-27 23:07
You should use different descriptions then. It will try verify all interactions that match the provider state and description.

uglyog
2020-05-27 23:12
People who access APIs though API gateways have this same problem. I normally recommend to try think about who the contract is between. > each module is responsible for different areas of the domain This does feel like there are separate concerns and maybe the BFF is jus the intermediary and multiple providers make sense.

uglyog
2020-05-27 23:13
Unless the BFF is modifying the downstream responses etc.

swaroopshere
2020-05-27 23:46
Hello, I have a question about verifying interactions in provider in pact-jvm. Is it possible to dynamically filter interactions that can be executed? One of the idiosyncrasies in our browser based Test runner UI frontend that is backed by JUnit 4, is, it can show test methods within a test class. Via the UI, I can select a test method to execute. With some tweaking, I hooked the UI frontend up with PactRunner, so it shows individual interactions in the UI test console, with the ability to select a particular interaction and execute. However, when I do that, I see that all interactions are run, regardless of which one is picked. Is there a way to override anything within PactRunner to say, "just run this interaction"?

uglyog
2020-05-28 00:27
The only way currently is to use provider states, and then filter by the provider state. But this seems like a useful feature, so please raise a issue for it on the Github project

ashish_garg5
2020-05-28 04:31
Hi All, Curious to know how would can-i-deploy check version compatibility ? I mean how it actually works ? Thanks.

tjones
2020-05-28 04:32
can-i-deploy checks with the broker to determine verification status between the versions you?re asking about in deployment

tjones
2020-05-28 04:33
if you?re deploying version 2 of a provider to a prod environment where version A of a consumer is, then it checks to see if ?consumer A <---> provider 2? has been verified

ashish_garg5
2020-05-28 04:33
yeah but how it actually verifies that the version will be compatible ?

tjones
2020-05-28 04:35
it asks the broker

tjones
2020-05-28 04:35
if the broker doesn?t know (ie, if the relevant verification status hasn?t been published to the broker), then can-i-deploy will say no

ashish_garg5
2020-05-28 04:36
ok

ashish_garg5
2020-05-28 04:38
in pact broker itself we can run the can-i-deploy command right ? //Something like this /can-i-deploy?pacticipant=PactConsumerJavaRest&version=1.0.0

ashish_garg5
2020-05-28 04:38
so it will check with the available provider whether it is compatible or not

ashish_garg5
2020-05-28 04:41
m checking like this in my pact broker

swaroopshere
2020-05-28 04:49
will do, thank you


francislainy.campos
2020-05-28 08:05
Okay, thank you. Will try it when working again on this piece and see if can make it work as per your suggestion.

aliihlail
2020-05-28 09:54
Hi All Is it possible to define more than one consumer to the same provider test? i mean sometimes i wrote the same rest test for different class.

wesleythomaswilliams
2020-05-28 09:55
I have a rest test which has multiple consumers for one provider.

wesleythomaswilliams
2020-05-28 09:58
So for example, I have a service that generates IDs. Different consumers make a request to that service with different input values to the service. So the service has states based on those inputs to serve each of the consumers.

aliihlail
2020-05-28 11:25
doest means that i need to remove the @Consumer annotaion

wesleythomaswilliams
2020-05-28 11:27
I know I don't use it, so quite possibly

mbieganski.infomatt
2020-05-28 11:33
It varies for me. I either share 1 State with multiple services, use Provider state parameters or have separate State for different response. I think it will not work with @Consumer annotation because you can pass only one

aliihlail
2020-05-28 11:34
i found an intresting thing that inside the @PactBroker you can define multiple consumer to the same provider

mbieganski.infomatt
2020-05-28 11:37
@uglyog @wesleythomaswilliams maybe you could have some idea. What should be the message format returned by the `@PactVerifyProvier` ? I'm playing around and returning ActiveMQTextMessage which doesn't work `com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 22 path $`

wesleythomaswilliams
2020-05-28 11:48
@mbieganski.infomatt In my provider test, I build a message object using the microservice code and then return it as a string. ```@PactVerifyProvider("a provider service update") public String providerServiceUpdateMessage() throws Exception { final ProviderServiceDtoV1 providerServiceDtoV1 = ProviderServiceDtoV1.builder() .thing() .anotherthing() .build(); return objectMapper.writeValueAsString(providerServiceDtoV1); }```

wesleythomaswilliams
2020-05-28 11:48
That's a massively cut down example

mbieganski.infomatt
2020-05-28 11:52
You are only returning body right? I'm wondering how to verify message with metadata e.g destination since we can include it in pact. I thought that I should return whole message but maybe I'm missing something..

wesleythomaswilliams
2020-05-28 11:52
Yeah, just the body

mbieganski.infomatt
2020-05-28 11:55
I couldn't find any other example though :pensive:

wesleythomaswilliams
2020-05-28 11:57
Ah wait, so the ProviderServiceDtoV1 object in our service include a metadata object.

wesleythomaswilliams
2020-05-28 11:58
Messaging you privately as working in this thread is a pain

matt.fellows
2020-05-28 12:52
How much of the docs have you read?


ashish_garg5
2020-05-28 14:33
Hi All, How can i pass JSONObject in PactDslJsonBody ? PactDslJsonBody responseBody = new PactDslJsonBody().stringType(jsonData.toString()); I am passing like this stringType(jsonData.toString()), but i want to pass json object itself which i am expecting in a response. Thanks.

ashish_garg5
2020-05-28 14:35
ok thanks i will check those docs.

wesleythomaswilliams
2020-05-28 14:40
Hi Ashish, I think the general advice is to avoid doing it if you can and make use of the matchers for PactDslJsonBody, but when I was starting out, I just used the Json like you're doing and still have some tests using it. ```@BeforeAll static void beforeAll() throws Exception { providerServiceResponse = StreamUtils.copyToString(new ClassPathResource("/json/pact/response.json").getInputStream(), Charset.defaultCharset()); }``` Then this in my builder: ```.body(providerServiceResponse)```

jarmy
2020-05-28 20:59
Hello. I?m writing a consumer jvm test for a Graphql provider and I?m curious how I?d include the equivalent of `{"query":"query Search{search(query: \"Drake\" types: [AR]) {items {id}}}"}` in the request of my `PactDslWithProvider` object. Does the jvm implementation have an equivalent of the pact-js `GraphQLInteraction` as described here? http://blog.pact.io/2018/07/24/contract-testing-a-graphql-api/ Here?s my existing code _without_ the query in the request ``` @Pact(consumer="PegasusConsumer") public RequestResponsePact searchItems(PactDslWithProvider builder) { return builder .given("Search items exist") .uponReceiving("a request to search for item data") .path("/graphql") .method("POST") .willRespondWith() .headers(headers) .status(200) .body( new PactDslJsonBody() .object("data") .object("search") .minArrayLike("items", 3) .stringType("id", "AR:306247") .stringType("id", "AR:623522") .stringType("id", "AR:396517") .closeArray() .closeObject() .closeObject() ) .toPact(); }```

uglyog
2020-05-28 23:12
Can you raise this as an issue on the Github project?


matt.fellows
2020-05-28 23:51
@jarmy thanks for raising this

matt.fellows
2020-05-28 23:53
Just so you know, the JS interface is a fairly lightweight shim over the existing interface. Because under the good, GraphQL actually sends a JSON payload with the gql query as a string, we construct a _very_ crude regex

matt.fellows
2020-05-28 23:53
so matchers and so on aren?t available - it really is just a string matcher

matt.fellows
2020-05-28 23:53
My point is that you could basically do that yourself now in the JVM interface, I think (happy to give you pointers)

jarmy
2020-05-28 23:54
I?ll happily take any pointers you can give

matt.fellows
2020-05-28 23:54
Long term, we need to detect that it is a GraphQL interaction (there is no standard media type, sadly, because it?s actually JSON) and then convert into a GraphQL AST and do the matchers that way - so it?s a bit more involved


matt.fellows
2020-05-28 23:57
All it does is this: 1. Takes the query, validates that it is indeed valid GraphQL syntax 2. Generates the JSON HTTP payload (this is just a convenience wrapper really) 3. Escapes the query string

matt.fellows
2020-05-29 00:03
It will produce a contract that looks a bit like this: ```{ "consumer": { "name": "GraphQLConsumer" }, "provider": { "name": "GraphQLProvider" }, "interactions": [ { "description": "a hello request", "request": { "method": "POST", "path": "/graphql", "headers": { "content-type": "application/json" }, "body": { "operationName": "HelloQuery", "query": "\n query HelloQuery {\n hello\n }\n ", "variables": { "foo": "bar" } }, "matchingRules": { "$.body.query": { "match": "regex", "regex": "\\s*query\\s*HelloQuery\\s*\\{\\s*hello\\s*\\}\\s*" } } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "data": { "hello": "Hello world!" } }, "matchingRules": { "$.body.data.hello": { "match": "type" } } } } ], "metadata": { "pactSpecification": { "version": "2.0.0" } } }```

uglyog
2020-05-29 00:03
I'm going to copy this thread onto the Github issue so we don't lose it

matt.fellows
2020-05-29 00:04
Ron - this should work similar to the XML stuff we recently did

matt.fellows
2020-05-29 00:04
One key difference is that it?s _both_ JSON and GraphQL

matt.fellows
2020-05-29 00:04
It?s all JSON/HTTP, except for the `query` parameter

ashish_garg5
2020-05-29 04:38
ok thanks

oscarg798
2020-05-29 07:16
has joined #pact-jvm

sabil.beladri
2020-05-29 08:09
Hi, are we already able to run a JVM spring-provider check against multiple versions for a same tag? As described at https://pact.canny.io/feature-requests/p/ability-to-ensure-compatibility-with-multiple-versions-of-a-consumer-in-producti Thanks for keeping me posted on that one & regards!

aliihlail
2020-05-29 08:14
```public class FeatureRestTest { private static final String AMENITIES_PATH = "/amenities"; private static final String FEATURES_IMPORT_PATH = "/features/import"; private static final String CONTENT_HEADER = HttpHeaders.CONTENT_TYPE; @Pact(consumer = "import-service", provider = "feature-service") public RequestResponsePact featureServiceGetPact(PactDslWithProvider builder) { return builder .given("amenity with name Elevator exist") .uponReceiving("GET request to retrieve city") .path(AMENITIES_PATH ) .query("name=Elevator") .method(HttpMethod.GET) .willRespondWith() .status(HttpStatus.OK.value()) .headers(responseHeaders()) .body(newJsonBody((amenity) -> { amenity.id("id"); }).getPactDslObject()) .toPact(); } @Pact(consumer = "import-service", provider = "feature-service") public RequestResponsePact featureServicePostPact(PactDslWithProvider builder) { return builder .given("post feature from import file") .uponReceiving("POST request to import feature") .path(FEATURES_IMPORT_PATH ) .method(http://HttpMethod.POST) .body(newJsonBody((amenity) -> { amenity.numberType("amenityId"); amenity.numberType("aggregateId"); amenity.stringMatcher("aggregateType", "UNIT|ROOM|BUILDING"); }).getPactDslObject()) .willRespondWith() .status(HttpStatus.CREATED.value()) .toPact(); } @Test @PactTestFor(pactMethod = "featureServiceGetPact") public void testGetFeatureService(MockServer mockServer) throws IOException { HttpResponse httpResponse = Request.Get(mockServer.getUrl() + AMENITIES_PATH + "?name=Elevator").execute().returnResponse(); assertEquals(httpResponse.getStatusLine().getStatusCode(), HttpStatus.OK.value()); } @Test @PactTestFor(pactMethod = "featureServicePostPact") public void testPostFeatureService(MockServer mockServer) throws IOException { HttpResponse httpResponse = http://Request.Post(mockServer.getUrl() + FEATURES_IMPORT_PATH).execute().returnResponse(); assertEquals(httpResponse.getStatusLine().getStatusCode(), HttpStatus.CREATED.value()); } private Map<String, String> responseHeaders() { Map<String, String> headers = new HashMap<>(); headers.put(CONTENT_HEADER, MediaTypes.HAL_JSON_UTF8_VALUE); return headers; } }``` Hi im trying to run this test for Get and Post. But with post it fails when i run the class. If i tried to run only the post test then it works fine. Any help how to to test post. or if there is any example that would be really amazing

francislainy.campos
2020-05-29 08:52
Hi all, good morning. So I'm trying to update our provider tests to use JUnit5 but they keep hanging on the screen and eventually time out and it's been a while trying to figure it out but not able to know why this is happening. I can run the consumer fine under the same repo. This is my whole provider piece if I could please get any pair of eyes on it. Many thanks.

matt.fellows
2020-05-29 08:54
That looks pretty clear to me - unable to reach your internal domain

matt.fellows
2020-05-29 08:54
Can you cURL / telnet or something to that host/port?

chandanakurumeti27
2020-05-29 09:07
Hi, I want to use regular expressions in expected request body in pact jvm, Can someone please provide any example on how to use it?

matt.fellows
2020-05-29 09:09
What docs have you looked at so far?

francislainy.campos
2020-05-29 09:11
Hi, thank you! Yeah, you're right. I was all this time thinking the error was on the PACT file but it was actually the url itself.


chandanakurumeti27
2020-05-29 09:24
but wanted to see any working example


chandanakurumeti27
2020-05-29 09:28
but didnt get clear picture of using regular expressions while defining the expected request in pact mock provider using pact jvm

francislainy.campos
2020-05-29 09:57
Sorry @matt.fellows, I think I may be a bit confused as still new to PACT, but we fixed the api however getting the same error still. Tried with both the full url and only the base one but keep getting the connection timeout.

francislainy.campos
2020-05-29 10:29
I don't understand why the error shows only the base path rather than the full url and I think that may be related to the issue, not sure.

chandanakurumeti27
2020-05-29 11:58
this is my expected body which i defined in pact mock provider

chandanakurumeti27
2020-05-29 11:58
playeruid above keeps on changing for every run of consumer tests

matt.fellows
2020-05-29 11:59
Can you try and connect to that host in your terminal? e.g. `telnet http://api.int.eng.hmhco.com 8080`

chandanakurumeti27
2020-05-29 11:59
so i want to use some reg exp or matchers while defining the expected request body so that it will accept the playeruid even after it chnages every time

matt.fellows
2020-05-29 11:59
The error is very clear to me - your IDE/Machine is unable to connect to that host

matt.fellows
2020-05-29 12:00
One thing I can?t see is why it?s trying to hit `8080` - should it be hitting that port or something else? It looks like it should be hitting a secure port (e.g. `443` or `8443` by convention)

chandanakurumeti27
2020-05-29 12:01
part of my consumer test where am defining the request body

chandanakurumeti27
2020-05-29 12:01
Please help me on this!, looking forward to any kind reply and help



wesleythomaswilliams
2020-05-29 12:08
@chandanakurumeti27 I don't think you need regex here. Taking the playerUid example, the contract is with the schema, so the value isn't important, so when building your PactDslJsonBody, you can use a line like .stringType("playedUid", "130"). The 130 part isn't strictly necessary it's just used as an example, but you're effectively just saying you expect playerUid to be a stringType. Will that suffice for you?

chandanakurumeti27
2020-05-29 12:13
yeah, as value of playeruid keeps on changing everytime, i just want to have that expected playeruid to be a string type

chandanakurumeti27
2020-05-29 12:14
but i want other values above like password and ispasswordencrypted to have exact same values

chandanakurumeti27
2020-05-29 12:14
so can i please have the syntax of my expected request body here ??

wesleythomaswilliams
2020-05-29 12:15
lol, I'll be super nice and write it for you. one sec

wesleythomaswilliams
2020-05-29 12:18
What I would do: ```final DslPart body = new PactDslJsonBody() .object("credential") .stringType("playerUid", "130") .stringType("password", "pjsvdkc12@44?§|[1") .closeObject().asBody() .booleanType("isPasswordEncrypted", false)``` That's how I'd do it personally, as I don't think you should be matching on exact values, regardless of if any of those values are changing or not.

chandanakurumeti27
2020-05-29 12:38
Thats so nice of you , thank you so much. I followed the above pact jvm repo and almost had the exact one like you sent above

chandanakurumeti27
2020-05-29 12:38
but was having this error `"http://au.com.dius.pact.consumer.dsl.DslPart cannot be converted to http://au.com.dius.pact.consumer.dsl.PactDslJsonBody"`

chandanakurumeti27
2020-05-29 12:39
as in README.md file above i have something like this ```PactDslJsonBody body = new PactDslJsonBody() .object("credential") .stringType("playerUid", "130") .stringType("password", "pjsvdkc12@44?§|[1") .closeObject().asBody() .booleanType("isPasswordEncrypted", false);```

chandanakurumeti27
2020-05-29 12:39
so corrected it to `DslPart body = new PactDslJsonBody()` and now its working

chandanakurumeti27
2020-05-29 12:39
thank you so much once again:+1::grinning:


wesleythomaswilliams
2020-05-29 12:58
@chandanakurumeti27 no problem at all :smile:

francislainy.campos
2020-05-29 13:58
Yeah, no. The api I can hit is this one https://api.int.eng.hmhco.com/update-catalog/v1/lastUpdateSummary but I don't know why the error shows just the base path for this url.

francislainy.campos
2020-05-29 14:00
8080 is just the port I have on my consumer from copying from some tutorials on the internet. I get a connection denied error with other ports. I'm on a vpn and a mac if that's make any difference?

francislainy.campos
2020-05-29 14:27
That's what I have on my consumer.

jarmy
2020-05-29 16:34
Can I get an ETA on when this can be implemented? I?m happy to help test the design.

mbieganski.infomatt
2020-05-29 20:03
Hey is there some way to handle `DateTimeFormatter ISO_ZONED_DATE_TIME` using `LambdaDslObject date`? There is ZonedDateTime but I'm unable to parse it to expected format `2020-01-01T10:00+01:00[Europe/Warsaw]`

matt.fellows
2020-05-29 23:59
I'm not sure. But I wouldn't wait as it's easy enough to do the basic version yourself.yoi basically just implement a regex on the query key, and do regular json matching on the rest. It shouldn't take you very long to create a convenience/helper/subclass that does the defaults for you

uglyog
2020-05-30 02:38
At the moment it only allows you to specify multiple tags, not versions.

uglyog
2020-05-30 02:40
What error do you get?

uglyog
2020-05-30 02:53
With ISO_ZONED_DATE_TIME looks like it's just an ISO date/time with the zone ID in the brackets. You can try match it with something like `yyyy-MM-dd'T'HH:mm:ssZZZ'['V']'`

uglyog
2020-05-30 02:53
`V` is the symbol for the zone ID

uglyog
2020-05-30 02:54
Actually, looks like you don't need to quote the brackets. See https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html

sairsule
2020-05-30 06:14
I keep on getting links to unavailable github repo links in Pact documentation like the one below. Any idea where this is moved to? https://github.com/DiUS/pact-jvm/blob/master/provider/pact-jvm-provider-maven/README.md#verifying-a-message-provider


uglyog
2020-05-30 06:43
Where are you getting the links from? They need to be updated

sairsule
2020-05-30 09:18
Thanks.


sairsule
2020-05-30 09:20
Are there any more examples of message Pacts? I am trying to implement this in kafka driven project. JVM or JS examples will do.

wesleythomaswilliams
2020-05-30 13:01
@sairsule I'm testing with pact-jvm and kafka, what's the schema for the message you want to verify?


chandanakurumeti27
2020-05-30 15:36
but the consumer service in my case is java based one, so someone please clarify whether this is possible in java as well?

chandanakurumeti27
2020-05-30 16:23
I found the same kind of issue https://github.com/DiUS/pact-jvm/issues/117, but couldnt really understand the solution provided here.

chandanakurumeti27
2020-05-30 16:37
I think i found the solution, I have added two provider names in this annoattion @PactVerification({?auth_For_Player?,?account_For_Player?}), started two mock providers at diff ports using @Rule and its working now

mbieganski.infomatt
2020-05-30 20:23
I have tried multiple configurations and no luck `http://au.com.dius.pact.consumer.MockServer)]: Illegal pattern component: V` eg. ```body.date("date", "yyyy-MM-dd'T'HH:mmZZZV", ZonedDateTime.parse("2020-01-01T10:00+01:00[Europe/Warsaw]"));``` Looks like the problem is that Pact is using FastDateFormat which seems to be based of SimpleDateFormat. Is there a plan to move to DateTimeFormatter?

uglyog
2020-05-30 23:07
Can you raise an issue for that?

sairsule
2020-05-31 07:28
I am not sure what you meant by schema, I want to check that a message is sent to a topic say "topic1" and payload has a key 'username'

wesleythomaswilliams
2020-05-31 12:47
By schema I mean the structure of the message, what keys are expected and what are the their respective data types. Contract testing services that write messages to kafka topics is pretty straightforward, because the kafka element is really not important. Here's a simple example from my own tests: Consumer Test: ``` @BeforeAll static void beforeAll() throws Exception { providerKafkaMessageFromJson = StreamUtils.copyToString(new ClassPathResource("/json/pact/providerKafkaMessage.json").getInputStream(), Charset.defaultCharset()); } @Pact(provider = "provider-service", consumer = "consumer-service") public MessagePact providerKafkaMessage(MessagePactBuilder builder) { final DslPart body = new PactDslJsonBody() .object("metaData") .stringType("origin", "provider-service") .datetimeExpression("dateCreated", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") .closeObject() .stringType("itemId", "9325858") .stringType("itemType", "Item"); return builder .expectsToReceive("a provider service message") .withContent(body) .toPact(); } @Test @PactTestFor(pactMethod = "providerKafkaMessage") public void testProviderKafkaMessage(MessagePact pact) throws Exception { // State final String messageFromPact = pact.getMessages().get(0).contentsAsString(); // Assert JSONAssert.assertEquals(messageFromPact, providerKafkaMessageFromJson, false); }```

wesleythomaswilliams
2020-05-31 12:53
Provider Test ``` @BeforeEach void setupTestTarget(PactVerificationContext context) { context.setTarget(new AmpqTestTarget()); } @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); } @PactVerifyProvider("an provider Kafka message") public String providerKafkaMessage() throws Exception { final MetaDataDtoV1 metaDataDtoV1 = MetaDataDtoV1.builder() .origin("provider-service") .dateCreated("2000-01-31T13:00:00.000Z") .build(); final ProviderServiceMessageDtoV1 providerServiceMessageDtoV1 = ProviderServiceMessageDtoV1.builder() .metaData(metaDataDtoV1) .itemId("9325858") .itemType("Item") .build(); return objectMapper.writeValueAsString(providerServiceMessageDtoV1); }```

sairsule
2020-05-31 14:20
I am confused for provider tests.


sairsule
2020-05-31 14:21
I could write pact test at consumer side. here's the code https://github.com/sairandhree/Spring-kafka-Receiver

wesleythomaswilliams
2020-05-31 14:29
Your consumer test looks ok, although consider using the matchers so that you're not doing comparisons on the actual data. How can I help with the provider side?

sairsule
2020-05-31 14:30
Thanks Wes,

sairsule
2020-05-31 14:31
I do not know what is PactVerificationContext and amqpTarget

sairsule
2020-05-31 14:31
am I missing any dependancies

wesleythomaswilliams
2020-05-31 14:33
I have: ```import au.com.dius.pact.provider.PactVerifyProvider; import au.com.dius.pact.provider.junit.Provider; import au.com.dius.pact.provider.junit.loader.PactBroker; import au.com.dius.pact.provider.junit.loader.PactBrokerAuth; import au.com.dius.pact.provider.junit5.AmpqTestTarget; import au.com.dius.pact.provider.junit5.PactVerificationContext; import au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider;```

wesleythomaswilliams
2020-05-31 14:34
If you're junit4 these are likely different

sairsule
2020-05-31 14:34
I am on junit5

sairsule
2020-05-31 14:36
got it, I was having comsumer-junit jar in my pom.xml

sairsule
2020-05-31 14:37
do I need to mark any class as AMPQTestTarget?

wesleythomaswilliams
2020-05-31 14:43
JUnit 5?s @TestTemplate feature is used in combination with PactVerificationInvocationContextProvider to dynamically create a test for every interaction found in the pact, so you just need to set the target for the context to AmpqTestTarget and annotate tests with @PactVerifyProvider.

sairsule
2020-05-31 14:46
Do you have a sample for provider please?


sairsule
2020-05-31 14:49
I would like to see it in project.

wesleythomaswilliams
2020-05-31 14:51
Ah, sorry, I can't share in the project as its taken from my work's project repository. What you see above is just a cutdown anonymised version.

wesleythomaswilliams
2020-05-31 14:51
Happy to answer questions though.

sairsule
2020-05-31 14:52
whats the type of ProviderServiceMessageDtoV1 and what is it returning

sairsule
2020-05-31 15:01
Also my pact has to be validated against MessageGenerator.generateMessage(). How do I tell that to Pact?

wesleythomaswilliams
2020-05-31 15:31
Our provider microservice builds a DTO object which it then writes out to Kafka as the message body. I reuse the DTO builders to build a message to compare my pact against in my provider test. I use the DTO builders as it is extra validation of the microservice's code. I could instead have just used a piece of json. This line then returns the object as a string for pact to compare against: ```return objectMapper.writeValueAsString(providerServiceMessageDtoV1);```

wesleythomaswilliams
2020-05-31 15:40
So I see your `MessageGenerator` class is doing the send to kafka. I wouldn't use that as part of the contract test myself, but if that class was modified a little, I could see how you could. Instead of: ``` public void generateMessage() throws JsonProcessingException { /// some procession... User user = new User (1L,"Bar"); sender.send("third_topic", "update", objectMapper.writeValueAsString(user) ); }``` Have: ``` public void sendMessage() { sender.send("third_topic", "update", generateMessage()); } public void generateMessage() throws JsonProcessingException { /// some procession... User user = new User (1L,"Bar"); return objectMapper.writeValueAsString(user); }``` Then in your provider test, you could do something like this (if my java brain is working today): ```    @PactVerifyProvider("an provider Kafka message")    public String providerKafkaMessage() throws Exception {        return MessageGenerator.generateMessage();    }```

sairsule
2020-05-31 15:40
@wesleythomaswilliams I updated my provider https://github.com/sairandhree/Spring-kafka-sender

sairsule
2020-05-31 15:40
It gives me error "provider State change callback failed"

sairsule
2020-05-31 15:42
could you please check what is it that I am doing wrong.

sairsule
2020-06-01 04:06
So Finally I could do it.

sairsule
2020-06-01 04:07
So Thanks you.


wesleythomaswilliams
2020-06-01 08:06
No problem, sorry I couldn't help more yesterday, had to spend some time with family :slightly_smiling_face:

sjuli.chen
2020-06-01 17:14
has joined #pact-jvm

dgaglani
2020-06-02 00:10
has joined #pact-jvm

dgaglani
2020-06-02 00:11
Hi.. I am using PACT test framework (on Java) .. I am stuck in creating array of interactions in pact programatically..  I know one way is: ```return builder .uponReceiving("a request for something") .path("/hello") .method("GET") .willRespondWith() .status(200) .body("{\"hello\": \"Ada\"}") .uponReceiving("another request for something") .matchPath("/hello/[0-9]+") .method("GET") .willRespondWith() .status(200) .body("{\"hello\": \"Ada\"}") .toPact();``` I am looking for creating array of interactions dynamically though loop.. how do I do that?

uglyog
2020-06-02 00:12
just put in the loop body ```builder .uponReceiving("a request for something") .path("/hello") .method("GET") .willRespondWith() .status(200) .body("{\"hello\": \"Ada\"}")```

dgaglani
2020-06-02 00:14
Also, I need to parse query parameters from a file as well and set it as matchQuery in a loop[

uglyog
2020-06-02 00:19
matchQuery takes a name, regex and example value. You will need to create those values from your file contents

dgaglani
2020-06-02 00:20
Thanks!! I have this in loop... ```for(Map.Entry<String, Request> entry: variableGenMap.entrySet()){ String responseBody = FileUtils.readFileToString(new File("test.json"),StandardCharsets.UTF_8); builder.uponReceiving(entry.getKey()) .method("GET") .matchPath(entry.getValue().getPath()) .willRespondWith() .body(responseBody) .status(HttpResponseStatus.OK.code()); }``` how do I call toPact() and return pactresponse?

uglyog
2020-06-02 00:21
`return builder.toPact()`

dgaglani
2020-06-02 00:22
builder is PactDslWithProvider. which does not have toPact() method

uglyog
2020-06-02 00:24
Ah, re-assign builder to the result in your loop

uglyog
2020-06-02 00:24
`builder = builder.uponReceiving...`

dgaglani
2020-06-02 00:29
tried this... does not work... ```PactDslResponse response = null; for(Map.Entry<String, Request> entry: variableGenMap.entrySet()){ String responseBody = FileUtils.readFileToString(new File("test.json"),StandardCharsets.UTF_8); response = builder.uponReceiving(entry.getKey()) .method("GET") .matchPath(entry.getValue().getPath()) .willRespondWith() .body(responseBody) .status(HttpResponseStatus.OK.code()); } return response.toPact();```

uglyog
2020-06-02 00:36
`response = response.uponReceiving`

dgaglani
2020-06-02 00:40
but `uponReceiving` method is from `PactDslWithProvider` class which will return `PactDslWithoutPath` and hence not compatible return type

uglyog
2020-06-02 00:42
They have a common base class

dgaglani
2020-06-02 00:49
not working.. do you have an example I can refer to?

uglyog
2020-06-02 00:49
No, sorry, there are no examples of anyone doing this in a loop

dgaglani
2020-06-02 00:49
similar issue with setting matchQuery in loop where I have to set matching parameters from a file

uglyog
2020-06-02 00:54
You're kind of on your own here. You might have to build the Pact object yourself, rather than using the DSL classes. You can look at what the DSL class methods are doing to get an idea of what you need to do

srinivasan.sekar1990
2020-06-02 06:54
@sairsule you can also refer to this if you still facing any issues - https://github.com/SrinivasanTarget/ContractTestingBoilerplate

sairsule
2020-06-02 07:11
@srinivasan.sekar1990 thank you.

aliihlail
2020-06-02 07:29
org.apache.http.NoHttpResponseException: 127.0.0.1:8080 failed to respond only the first class managed to respose correctlly only the first

uglyog
2020-06-02 07:35
You need to get the Apache HTTP client to stop caching connections.

uglyog
2020-06-02 07:36
You can try ```@After void teardown() { Executor.closeIdleConnections() }```

uglyog
2020-06-02 07:36
But it depends on the version of the Apache HTTP client you are using

aliihlail
2020-06-02 07:38
Apache-HttpClient/4.5.6 this is what im using

aliihlail
2020-06-02 07:46
it doesnt worked.

uglyog
2020-06-02 07:51
You can try a Thread.sleep(2000) in the after method

wesleythomaswilliams
2020-06-02 09:53
@srinivasan.sekar1990 That's really handy, thanks for sharing. Saves me pasting code snippets everywhere :smile:

mbieganski.infomatt
2020-06-02 11:05
Hi. Looks like Pact is adding default response "Content-Type" header even if it's not included in contract. ``` "Content-Type" with value "application/json; charset=UTF-8"``` Is there a way to disable it or way to test response that has empty headers?

uglyog
2020-06-02 13:08
It will default to either JSON or text. It needs to know the content type so that it knows how to deal with the body.

uglyog
2020-06-02 13:08
If you specify the content type header yourself, it will not default

mbieganski.infomatt
2020-06-02 13:13
problem is that pact expects headers to exists but in my case response have empty headers and if I would like to verify body test fails

sabil.beladri
2020-06-02 16:40
Many thanks for clarifying this one @uglyog ! Also please let me know in case I can check progress on that subscribing or watching a github ticket.

rjaladurgam
2020-06-02 16:42
My Spring provider test gives below error. Any help that could be provided? Caused by: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

rjaladurgam
2020-06-02 18:29
Could SpringBootHttpTarget be used along with @WebMVCTest for Testing REST Controllers (API) written with Spring Boot?

dgaglani
2020-06-02 19:56
Hi.. I kinda created interactions with loop in pact object by looping... ```pact = builderWithPath.willRespondWith() .headers(headers) .body(responseBody) .status(HttpResponseStatus.OK.code()).toPact();``` I have this consumer unit test case which will hit mock endpoint with request parameters with each interactions: ```variableMapList.forEach((queryMap) -> { HttpUriRequest request = buildRequest(mockProvider.getPort(),queryMap); CloseableHttpClient httpClient = HttpClients.createDefault(); try { httpClient.execute(request); } catch (IOException e) { e.printStackTrace(); } });``` When I run this unit test, it throws this error: ```Unexpected Request: method: GET path: /api/v2/gql/content_view query: [notification:[true] headers: [Accept-encoding:[gzip,deflate], Connection:[Keep-Alive], Host:[localhost:62563], User-agent:[Apache-HttpClient/4.5.5 (Java/1.8.0_212)]] matchers: MatchingRules(rules={}) generators: Generators(categories={}) body: EMPTY``` Same parameter and request works fine with single interaction

dgaglani
2020-06-02 19:57
`pact` object does have interactions which I can see from debug mode

dgaglani
2020-06-02 21:58
actually now I am getting this error: out of 3 requests, failed for 2 and works for 1st request send... ```au.com.dius.pact.consumer.PactMismatchesException: The following requests were not received: method: GET path: /api/v1/gql/content_view query: [notification:[true]] headers: [:] matchers: MatchingRules(rules={path=Category(name=path, matchingRules={=MatchingRuleGroup(rules=[RegexMatcher(regex=/api/v1/gql/content_view, example=null)], ruleLogic=AND)}), query=Category(name=query, matchingRules={notification=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), site=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), caasAppId=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), namespace=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), id=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), region=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), lang=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), device=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), uuid=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), version=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), caasFeatures=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND)})}) generators: Generators(categories={}) body: MISSING method: GET path: /api/v1/gql/content_view query: [notification:[true]] headers: [:] matchers: MatchingRules(rules={path=Category(name=path, matchingRules={=MatchingRuleGroup(rules=[RegexMatcher(regex=/api/v1/gql/content_view, example=null)], ruleLogic=AND)}), query=Category(name=query, matchingRules={notification=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), site=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), caasAppId=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), namespace=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), id=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), region=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), lang=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), device=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), uuid=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), version=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND), caasFeatures=MatchingRuleGroup(rules=[RegexMatcher(regex=.*, example=null)], ruleLogic=AND)})}) generators: Generators(categories={}) body: MISSING```

dgaglani
2020-06-02 22:27
@uglyog how do we create consumer unit test to work with array of interactions in pact?

uglyog
2020-06-02 23:02
No, SpringBootHttpTarget is for testing the actual springboot app

uglyog
2020-06-02 23:34
Sorry, I'm not sure what you're trying to accomplish here. Pact is designed to test the interactions in isolation. Looks like you are trying to do some type of automated integrated testing. There are better tools out there for doing that.

jarmy
2020-06-03 00:09
I?m ready to give this a shot. Can you point me to the `XML stuff we recently did` so I can get an idea on how I?d implement things?

matt.fellows
2020-06-03 00:29
awesome

matt.fellows
2020-06-03 00:29
the XML stuff we recently did thing is a note that will only make sense for Ron in the long term

matt.fellows
2020-06-03 00:29
unless you?re keen to get stuck into Rust code for solving it in other languages too? :stuck_out_tongue:

matt.fellows
2020-06-03 00:30
The pointers I?ve given you above in JS should be a good start

rjaladurgam
2020-06-03 06:30
Thank you for the reponse

sbartsa
2020-06-03 07:59
has joined #pact-jvm

ale.paciello
2020-06-03 08:14
has joined #pact-jvm

ale.paciello
2020-06-03 08:17
Hello! Any tip on how install a development version of pact-jvm in local maven repository using gradle? By running the `publishToMavenLocal` task the jars are placed in the correct folders but no metadata-local file is generated. Thank you!

shawn.edge
2020-06-03 13:48
has joined #pact-jvm

jacek.okrojek
2020-06-03 15:15
has joined #pact-jvm

dgaglani
2020-06-03 17:52
@uglyog I am trying to create unit test similar to : https://github.com/DiUS/pact-jvm/blob/master/consumer/junit/src/test/java/au/com/dius/pact/consumer/junit/pactproviderrule/PactProviderWithMultipleFragmentsTest.java#L107 except that I have all GET method call with different param values... But for me, it accepts first request, but fails for subsequent requests with error: `http://au.com.dius.pact.consumer.PactMismatchesException: The following requests were not received:`

jarmy
2020-06-03 21:52
I?m following the _Buidling the library_ directions https://github.com/DiUS/pact-jvm/wiki/How-to-contribute-to-Pact-JVM and trying to build a local snapshot of `pact-jvm` with `./gradle clean install` AFAICT, snapshots aren?t getting built or published to my local maven repository. Are there more up-to-date directions elsewhere?

uglyog
2020-06-03 23:08
If you're using the Apache HTTP client, it caches connections which will cause that error. You need to either disable that or add a sleep between tests.

uglyog
2020-06-03 23:10
I use publishToMavenLocal, it works ok for me

uglyog
2020-06-03 23:12
Gradle projects don't create snapshots or publish artefacts to the Maven repo. That is a Maven thing. You can use the `publishToMavenLocal` Gradle task to put the artefacts in your local repo.

jarmy
2020-06-03 23:17
I ended up using `publishToMavenLocal`

mail961
2020-06-04 00:57
hi, I?m currently trying to write a pact test with an http target for a spring boot application. the provider test runs fine in the IDE, but when I call ?mvn pact:verify? I get a ?Connection refused? for localhost:8080, when pact tries to call the spring service (?mvn install? runs the tests without problems). Does anybody know what I?m doing wrong?

uglyog
2020-06-04 00:59
`mvn pact:verify` is not for running Pact unit tests. Just run `mvn verify`

mbieganski.infomatt
2020-06-04 04:39
Hey @uglyog Just wanted to clarify pactbroker.providerTags for pending pacts. If i have feature branch "test" and master then i set pactbroker.providerTags with one of them depending which pipeline is running?

uglyog
2020-06-04 04:41
As far as I understand it, pactbroker.providerTags must be set to the tag that the provider verification result is tagged with. It depends on your pipeline

mbieganski.infomatt
2020-06-04 04:54
So sounds about right. Example : Publish new contract from pipeline "test" this will trigger webhook to run provider verifification from master so providerTags=master. When i would run provider verification from branch "feature" then providerTags=feature? I Just want double check due to question i left on #pact-broker channel..

uglyog
2020-06-04 05:03
No, I think providerTags must always be master.

uglyog
2020-06-04 05:04
The feature branch pacts will be pending because there will be no verification results tagged with master for them

mbieganski.infomatt
2020-06-04 05:23
Isn't this correct? Consumer changed pact tagged "test" then it was verified by webhook "master" which should fail and is pending. So then provider branch "test" matching consumer is executed and pass so pact isnt pending anymore?

uglyog
2020-06-04 05:37
No, I don't think so. But @bethskurrie is the one who can confirm

mbieganski.infomatt
2020-06-04 05:55
Had the same idea :slightly_smiling_face: i have also read the blog entry and demo but maybe I'm missing something. https://github.com/pactflow/ci-cd-workshop/blob/master/workshop/02_protecting_the_provider.md

mail961
2020-06-04 05:57
hi uglyog. thanks, for the prompt response. with just `mvn verify` it works. What is `mvn pact:verify` for then? Based on https://github.com/DiUS/pact-jvm/tree/master/provider/maven#3-execute-mvn-pactverify I assumed it was responsible for running the tests and uploading the results.

bethskurrie
2020-06-04 09:17
The webhook flow does not use pending because it's just passing the specific pact url through to the verification.

bethskurrie
2020-06-04 09:17
The webhook does not know which provider tags will be used to verify the pact, and hence, it can't know if the pact will be pending or not.

bethskurrie
2020-06-04 09:18
The pending functionality only applies to the "provider changed" workflow, where the provider is fetching the configured pacts from the broker.

bethskurrie
2020-06-04 09:20
> Isn't this correct? Consumer changed pact tagged "test" then it was verified by webhook "master" which should fail and is pending. So then provider branch "test" matching consumer is executed and pass so pact isnt pending anymore? The pact would be pending on provider master still, but not pending on provider test.

bethskurrie
2020-06-04 09:22
The pending calculation is always based on the provider tags. If the content has not been successfully verified by a certain provider tag, it is pending for that tag. Once it has been successfully verified by that provider tag, it is no longer pending for that tag, but it remains pending for all other tags.

mbieganski.infomatt
2020-06-04 09:24
yes. so basically pactbroker.providerTags = branch of the current provider

bethskurrie
2020-06-04 09:24
Yes

mbieganski.infomatt
2020-06-04 09:25
great! Thanks again!

bethskurrie
2020-06-04 09:25
Tag with the branch when you build, tag with the environment when you deploy.

bethskurrie
2020-06-04 09:25
I'm actually going to add explicit branch support, because people get confused about tags and branches.

bethskurrie
2020-06-04 09:26
It will make it simpler to explain, even though it will be the same underlying logic.

mbieganski.infomatt
2020-06-04 09:26
this is clear for me :slightly_smiling_face: I only got confused about not failing builds

jarmy
2020-06-04 21:00
I?m looking for some help with the implementation details. Would I be correct to add a new class (e.g. `PactDslGraphQLRequest`) under `http://au.com.dius.pact.consumer.dsl`? Would this new class extend from `PactDslRequestBase`? Am I barking up the wrong tree?

jks
2020-06-04 21:08
Hello, I have a question about the DSL. I?ve noticed the PactDslJsonBody class doesn?t create JSON with the same order as coded. For instance, this code: ```subject .array('array1') .object().stringValue('foo', 'b').closeObject() .object().stringValue('foo', 'a').closeObject() .closeArray() .array('array2') .number(1).number(2).number(3).number(4) .closeArray() .close()``` Produces: `{"array2":[1,2,3,4],"array1":[{"foo":"b"},{"foo":"a"}]}` When I?d expect: ```'{"array1":[{"foo":"b"},{"foo":"a"}],"array2":[1,2,3,4]}'``` It seems the PactDslJsonArray class preserves order, which I would expect. From a JSON perspective it may not matter. Just wondering if there is a reason, or just a side effect. I?m writing some tests for PactDslJsonBodyMatcherSpec and want to make sure I do it in a way that works into the future.

matt.fellows
2020-06-04 23:18
I might need @uglyog to help out with that specific advice (I?m not intimately familiar with the class hierarchy etc.), but I?d start with writing a standard test as per above and getting it to work. Once you?ve got that working, extract it out into a base class as you suggest

uglyog
2020-06-04 23:57
Seems like a reasonable place to start

jarmy
2020-06-05 00:01
okay. thanks

dgaglani
2020-06-05 00:04
How do I set matcher which has field which can either have value string or can be null? I tried this: ```"$.data.displayName": { "matchers": [ { "match": "type", "value": "Hello" }, { "match": "null" } ], "combine": "OR" }``` This does not work in case actual response from server for displayName is null


uglyog
2020-06-05 00:12
Better to have two tests, one with the values and one where they are missing.

dgaglani
2020-06-05 00:22
but values are dynamic.. depending on other factors which provider / consumer does not care if null or not.. hence want to ignore

uglyog
2020-06-05 00:28
If the consumer doesn't care about the attributes, leave them out of the contract

phil.endsley
2020-06-05 05:08
has joined #pact-jvm

thomas.koerner
2020-06-05 07:50
has joined #pact-jvm

alex810
2020-06-05 08:05
has joined #pact-jvm

thomas.fisher
2020-06-05 08:28
has joined #pact-jvm

jks
2020-06-05 13:14
Disregard, found examples of how to deal with this.

dgaglani
2020-06-05 16:31
Thanks!

raghulraj
2020-06-07 20:34
has joined #pact-jvm

steven.knopf
2020-06-08 08:32
has joined #pact-jvm

r.iglesias
2020-06-08 09:43
has joined #pact-jvm

sonney.patel
2020-06-08 12:31
has joined #pact-jvm

rafael.espillaque
2020-06-08 12:51
has joined #pact-jvm

ryan.dens
2020-06-08 13:07
:wave: Curious if someone has experience with writing Pacts whose request bodies have been gzip?d? I stumbled across this old issue for ?pact-js? to add support for content encodings: https://github.com/pact-foundation/pact-js/issues/93. In that issue, it is suggested that content encodings are a transport concern handled by underlying libraries and is therefore not a good candidate for inclusion in the contract. I tend to very much agree, so ordinarily this would end here, however I have some nastiness in the API provider I work with which deviates from best practices from handling content encodings. I don?t remotely expect Pact to have an optimal UX for this uncommon use case, but I would like to be able to have gzip?d JSON bodies as one of my contracts. Right now, when I attempt to do this, I get a JSON parse exception. I can see there is an open issue here on pact-jvm: https://github.com/DiUS/pact-jvm/issues/556 which suggests that what I?m looking for is outside the scope of the decision made on the pact-js issue. I think the best path forward would be to include the `Content-Encoding` header in `lookupBodyMatcher` and to use the `PlainTextBodyMatcher` if it is gzip?d, but curious to see what others have done

sonney.patel
2020-06-08 13:09
Hello there, I just spoke to someone in #general who redirected me here. I'm writing pact tests in java, have successfully published the consumer test, however i'm receiving 401 when i attempt to reconcile it on the providers side. Our provider does have basic authentication, but I'm not sure where to configure this. I'd appreciate any help

ryan.dens
2020-06-08 13:13
There?s a helpful portion of the docs on this: https://docs.pact.io/provider/handling_auth#docsNav My team has found success using #2, however I suspect using a request filter as specified in #4 would be a good general purpose solution

sonney.patel
2020-06-08 13:16
ooh thank you ill check this out

matt.fellows
2020-06-08 13:46
Basic auth :nauseated_face:. You could just put the creds for your test environment in the contract if they aren't sensitive

matt.fellows
2020-06-08 13:46
That would be the simplest

sadeed.bari
2020-06-08 14:08
has joined #pact-jvm

christopher.kies
2020-06-08 14:13
has joined #pact-jvm

sonney.patel
2020-06-08 14:23
I looked to do #4 because it made the most sense to me when i read it and i found this annotation @TargetRequestFilters where HttpRequest is passed as a parameter, however I couldn't invoke the method when i ran the test :angry:

sonney.patel
2020-06-08 14:24
@matt.fellows I might be able to do that, but i need to talk to my team first

v.scherr
2020-06-08 15:12
has joined #pact-jvm

v.scherr
2020-06-08 15:13
Im writing a small programm for a University project. I'd like to test it with the pact framewok. Unfortunately, no Pact.json file is created for me, although there are no errors. My Consumer iss written in Javascript. Below you can see the source code of my javascript file, the console output and my package.json file: ```const {Pact} = require('@pact-foundation/pact'); const axios = require('axios'); const path = require('path'); jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000 describe('Pact Consumer', () => { const provider = new Pact({ consumer: 'consumer', provider: 'producer', port: 1234, cors:true, log: path.resolve(process.cwd(), 'logs', 'pact.log'), dir: path.resolve(process.cwd(), 'pacts'), logLevel: 'INFO', }); beforeAll(() => provider.setup()); describe('consumer', () => { beforeAll ((done) => provider.addInteraction({ uponReceiving: "a request for JSON data", withRequest: { method: "GET", path: "/test", headers: { Accept: "application/json" }, }, willRespondWith: { status: 200, headers: { "Content-Type": "application/json","Access-Control-Allow-Origin": '*' }, body: { name: 'Scherr', surname: 'Valerian', age: 28, }, }, }) .then(done, error => done.fail(error)), ); }); describe('test', () => { it('should return the correct data', () => { axios.get('localhost:8888/test').then(response => { expect(response[0].name).toBe('Scherr'); expect(response[0].surname).toBe('Valerian'); expect(response[0].age).toBe(28); }) }); }); afterEach(() => { provider.verify(); }); afterAll(done => { provider.finalize().then(done, done.fail); }); });``` Console output:`"C:\Program Files\nodejs\node.exe" C:\Users\vsche\IdeaProjects\testscenario\webservice\node_modules\jasmine\bin\jasmine.js --reporter=C:\Users\vsche\.IntelliJIdea2019.3\config\plugins\IdeaJasmine\lib\intellij_reporter.js C:/Users/vsche/IdeaProjects/testscenario/webservice/spec/WebService.spec.js --filter=test` [2020-06-08T15:05:38.629Z] INFO: pact-node@10.9.5/8152 on DESKTOP-FH2DU0O: Creating Pact Server with options: {"consumer":"consumer","cors":true,"dir":"C:\\Users\\vsche\\IdeaProjects\\testscenario\\pacts","host":"127.0.0.1","log":"C:\\Users\\vsche\\IdeaProjects\\testscenario\\logs\\pact.log","pactFileWriteMode":"overwrite","port":1234,"provider":"producer","spec":2,"ssl":false} [2020-06-08T15:05:39.679Z] INFO: pact@9.11.0/8152 on DESKTOP-FH2DU0O: Setting up Pact with Consumer "consumer" and Provider "producer" using mock service on Port: "1234" [2020-06-08T15:05:39.700Z] INFO: pact@9.11.0/8152 on DESKTOP-FH2DU0O: Pact File Written [2020-06-08T15:05:39.701Z] INFO: pact-node@10.9.5/8152 on DESKTOP-FH2DU0O: Removing Pact process with PID: 13428 [2020-06-08T15:05:41.800ZPact verification failed!] INFOPopsicleError: Unable to connect to "http://127.0.0.1:1234/interactions" : pact-node@10.9.5/8152 on DESKTOP-FH2DU0O: Caused by: Error: connect ECONNREFUSED 127.0.0.1:1234 Deleting Pact Server with options: {"consumer":"consumer","cors":true,"dir":"C:\\Users\\vsche\\IdeaProjects\\testscenario\\pacts","host":"127.0.0.1","log":"C:\\Users\\vsche\\IdeaProjects\\testscenario\\logs\\pact.log","pactFileWriteMode":"overwrite","port":1234,"provider":"producer","spec":2,"ssl":false} Thanks in advance for any help

phil.endsley
2020-06-08 15:45
The pact json is generated by the consumer, so you'll probably get more help in the #pact-node channel

v.scherr
2020-06-08 15:48
Thank u. I write to #pact-node

aliihlail
2020-06-08 16:24
I have an issue with publishing the verification results of the Amqp testing to the pact broker. when the results passes. this is only when there are multiple consumers for the same provider. When tests fails it can publish that results.

antonello
2020-06-08 20:36
Any chance of a release of pact-jvm soon? :blush:

jarmy
2020-06-08 23:24
@matt.fellows What is this code doing exactly? ```const escapeGraphQlQuery = (s: string) => escapeSpace(escapeRegexChars(s)) const escapeRegexChars = (s: string) => s.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") const escapeSpace = (s: string) => s.replace(/\s+/g, "\\s*")``` https://github.com/pact-foundation/pact-js/blob/master/src/dsl/graphql.ts#L113-L118

matt.fellows
2020-06-08 23:29
I?ve responded to your SO question Valerian

matt.fellows
2020-06-08 23:31
It?s escaping certain characters and allowing a regex match on the query (and allowing spaces)

matt.fellows
2020-06-08 23:32
I can?t exactly remember why the regex was necessary, because if you can control the query then you should be able to control spaces etc. It may have been that I experienced a breaking Pact change upgrading minor version of Apollo or something so guarded against it.

matt.fellows
2020-06-08 23:32
You could see how you go without that initially

matt.fellows
2020-06-08 23:32
The key thing is that you can get the `query` attribute to have the exact string that your GraphQL client sends

raghulraj
2020-06-09 02:12
Hi All, facing an issue in my springboot app while running mvn pact:verify, its not starting the mock server, but when it got triggered like a junit test it works. Any idea?

raghulraj
2020-06-09 02:13
``` Given Create customer for an existing Account WARNING: State Change ignored as there is no stateChange URL create customer call to custmart-service returns a response which has status code 200 (FAILED) has a matching body (FAILED)```

raghulraj
2020-06-09 02:13
```assert expectedStatus == actualStatus | | | 200 | 404 false```

uglyog
2020-06-09 02:19
`mvn pact:verify` does not start the mock server. It should be run against your actual springboot app. You will need to ensure your app is started before hand. If you are using the JUnit Spring runner, it will automatically start the springboot app using the Spring test support.

raghulraj
2020-06-09 02:30
ok. Thanks for the quick response, will check.

raghulraj
2020-06-09 03:53
i am using junit4 ```@RunWith(SpringRestPactRunner.class)```

raghulraj
2020-06-09 03:54
which is running fine, when i trigger it from IDE.

raghulraj
2020-06-09 03:55
But springboot app is not starting when i run mvn pact:verify.


uglyog
2020-06-09 04:21
don't use `mvn pact:verify`, use `mvn verify`

raghulraj
2020-06-09 05:15
cool. That worked. Thanks

v.scherr
2020-06-09 10:16
Thank u i have a new failure i updated my code on stackover

anddreiu
2020-06-09 10:40
Hi. I've just upgraded the provider library from 4.0.4 to 4.1.1, but I have some issues with `PactRunner.class` and `HttpTarget` which cannot be resolved to a type. I've looked over the Release notes (https://github.com/DiUS/pact-jvm/releases) but didn't figure if these were changed and if I have to change the implementation. Also, in the documentation (https://github.com/DiUS/pact-jvm/tree/v4.1.x/provider/junit) I can still see those classes used. I am using Junit 4.

raghulraj
2020-06-09 15:15
Hi @uglyog though tests are passed, it shows ```Tests run: 0, Failures: 0, Errors: 0, Skipped: 0```

raghulraj
2020-06-09 15:15
when use mvn verify

raghulraj
2020-06-09 15:20
also it skips publishing of verification results, though it set to true.

rafael.espillaque
2020-06-09 16:27
Hi all, what?s the best way of analysing/rendering this kind of errors? junit log doesn?t seem very helpful

rafael.espillaque
2020-06-09 16:29
I guess the I can use this part of the message: `mismatch=Expected id="string" but was missing` but I wonder if there?s a tool that is able to parse those errors

raghulraj
2020-06-10 00:15
Hi @uglyog, with `mvn pact:verify` it's updating the results to pact broker. but not with `mvn verify`. how to fix this?

uglyog
2020-06-10 00:23
@raghulraj if Maven is not running your test, then the results will be not published because the test does that. This has nothing to do with Pact, you need to work out why the test is not running. Consult the Maven Surefire documentation, because that is what runs the tests when you execute `mvn verify`.

raghulraj
2020-06-10 00:23
my bad, just tested it.. mvn verify is running it, but results shows 0

raghulraj
2020-06-10 00:23
its updating it as failure in pact broker

raghulraj
2020-06-10 00:26
```Verifying a pact between Ms1 customer regristrion ui and custmart-service Given Create customer for an existing Account create customer call to custmart-service .... returns a response which has status code 200 (OK) has a matching body (OK) [INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 9.531 s - in com.custmart.pact.Custmart_Create_Customer_ProviderPactTest [INFO] [INFO] Results: [INFO] [INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 [INFO] ```

raghulraj
2020-06-10 00:29
command used: ```mvn verify -Dpact.verifier.publishResults=true -Dpact.provider.version=1.0.0```

raghulraj
2020-06-10 00:32
broker shows: ```"testResults": [ { "interactionId": "d2bb56ec9e2ad448eac2713932a26d5f06f34025", "success": false, "mismatches": [ { "attribute": "status", "description": null }, { "attribute": "body", "description": "null" } ] } ],```

uglyog
2020-06-10 00:33
What versions of Pact-JVM and Maven are you using?

raghulraj
2020-06-10 00:38
```<dependency> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-provider-spring</artifactId> <version>4.0.10</version> </dependency> <dependency> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>4.0.10</version> </dependency>```

uglyog
2020-06-10 00:39
Sorry, I meant the version of Maven

raghulraj
2020-06-10 00:40
```<maven.surefire.plugin.version>2.22.1</maven.surefire.plugin.version>```

raghulraj
2020-06-10 00:42
```Apache Maven 3.6.3 ```

uglyog
2020-06-10 00:45
You need to enable debug logging to see what is going on.

raghulraj
2020-06-10 00:48
ok

godfrey
2020-06-10 07:35
has joined #pact-jvm

matt.fellows
2020-06-10 08:05
Thanks Anto!

matt.fellows
2020-06-10 08:05
(and team at Treatwell)

cristian.schez
2020-06-10 08:22
has joined #pact-jvm

anddreiu
2020-06-10 09:06
@uglyog can you please take a look on this? I just want to know if I am doing something wrong or if it's an issue on this version. Thanks.

wesleythomaswilliams
2020-06-10 10:15
Are all the tests in a single class? I'd be interested in seeing it if you can share. Also, any output from the test execution.

wesleythomaswilliams
2020-06-10 10:18
I usually copy the first line into an editor for closer analysis. I find the diff part quite hard to read and just look at the actual and expected myself.

wesleythomaswilliams
2020-06-10 10:19
Btw, your failure is casing id != ID

rafael.espillaque
2020-06-10 10:22
I see, thanks

antonello
2020-06-10 11:34
You?re welcome, @matt.fellows! My first attempt at writing Kotlin!

antonello
2020-06-10 11:35
There is an unrelated failing tests, but apart from that it should be good to go!

slack1274
2020-06-10 11:41
has joined #pact-jvm

wvdbraak
2020-06-10 12:02
has joined #pact-jvm

uglyog
2020-06-10 22:57
The module names have changed. See https://github.com/DiUS/pact-jvm/releases/tag/4_1_0 for the details

jarmy
2020-06-11 00:12
Hi @uglyog I?ve got my `PactDslGraphQLRequest` class in place which `extends PactDslRequestBase` and would like to test some of the methods I?ve written. How exactly do the methods in here https://github.com/DiUS/pact-jvm/blob/master/consumer/src/test/java/au/com/dius/pact/consumer/MatchingTest.java#L87 map to their respective classes? For example, both `PactDslRequestWithPath` and `PactDslRequestWithoutPath` contain `method(String method)` yet this line resolves to the one in _PactDslRequestWithPath._ For that matter, how does the test become context aware of classes such as `PactDslGraphQLRequest`?

uglyog
2020-06-11 00:24
Those two classes work together to create the DSL, they are really just historical and one class is fine. Probably could refactor them into one class in the future. That test just uses the DSL (see line 162) and doesn't even know about the individual classes.

antonello
2020-06-11 09:25
@uglyog I saw you removed `appveyor` but it?s still running on PRs

ashish_garg5
2020-06-11 11:12
Hi All, How i can publish the consumer app version using command line. I don't want to take it from my pom.xml. In provider side i am able to do it by passing -Dpact.provider.version=1.0.0 Thanks.

rafael.espillaque
2020-06-11 11:49
I?d try to use `projectVersion` in the maven pact plugin config and set it to a custom project property and then use -DyourProperty=xxx


ashish_garg5
2020-06-11 11:50
ok thanks

wesleythomaswilliams
2020-06-11 12:42
We do this in our pipeline: ```'mvn test -Dpact.provider.version=' + env.GIT_COMMIT '-Dpact.verifier.publishResults=true' + ' -Dpact.provider.tag=' + env.GIT_BRANCH```

satya.quote_pact
2020-06-11 13:45
has joined #pact-jvm

satya.quote_pact
2020-06-11 13:52
Apologies if this has been asked here already, Quick question any pointers for getting secrets from vaults while verifying the pact with secrets in it. Don't want to hardcode that in the published pact but wanted to get on runtime

matt.fellows
2020-06-11 22:02
Why do you have secrets in your pacts? As a general rule it should all be test data that you can control, but I'm keen to understand further. In java at least, you could use request filters to dynamically replace secrets

bradley.smith
2020-06-11 23:03
has joined #pact-jvm

ashish_garg5
2020-06-12 05:35
@wesleythomaswilliams - Hey thanks but i was asking for the consumer side... projectVersion tag worked for me :slightly_smiling_face:

satya.quote_pact
2020-06-12 12:09
Yes agree all the data we are passing is test data which is been setup as state change. However it requires some authentication secrets which could not be exposed in pacts. So wondered if there is any option for doing so. Yeah will look into filters to dynamically replacing it.

aliihlail
2020-06-12 15:33
Yes. they are in a single class.

aliihlail
2020-06-12 15:34
Thread.sleep(2000) also does not worked

matt.fellows
2020-06-13 09:15
Ron on a PR purge!

vivek.thangathurai
2020-06-13 14:14
has joined #pact-jvm

antonello
2020-06-15 22:34
Is there a way to apply a like matcher to a whole Json body as you could do in JavaScript with like?

uglyog
2020-06-15 23:34
Can you provide an example?

srikanth.chikkala
2020-06-16 04:03
has joined #pact-jvm

mbieganski.infomatt
2020-06-16 13:36
hey. is there a way to make name matching any String? Like case where Object is a Map and property name can be any String?

phil.endsley
2020-06-16 16:55
I'm trying to wrap my head around what our workflow will look like with pending pacts. I've read through some of the docs (ci/cd workshop, pact-jvm-provider) , but still have a couple questions 1. Consumer team publishes a new/updated contract 2. Provider verifies the specified tags like normal. 3. In addition, the provider will verify any Pacts that have not been verified by the latest version of the specified provider tag 4. If the pending pacts fail, no change. If they pass, results are published and they're no longer pending for that provider version Is that correct? The junit 5 jvm provider docs say: > You also need to provide the tags used to publish the providers main-line results (i.e. tags like prod or master) https://github.com/DiUS/pact-jvm/tree/master/provider/junit5#pending-pact-support-version-410-and-later Is this supposed to be hard coded to a branch, and stay that way for all feature branches (With the assumption that you only publish verification results from CI server)? If that's the case, is the intended workflow for the provider: 1. Manually update the tags you verify against to include the consumer feature 2. Implement like normal 3. Remove the consumer feature tag before merging? I guess it all boils down to, what is the providerTags parameter actually used for?

phil.endsley
2020-06-16 19:12
Still have questions, but I think part of my issue was I was treating WIP pacts and pending pacts as the same feature. According to this table https://docs.pact.io/feature_support, it doesn't look like wip pacts are supported for jvm yet. Is there an open issue for this?

antonello
2020-06-16 19:43
@phil.endsley I thought that pending pacts was just the new, better name for WIP pacts.

antonello
2020-06-16 19:44
@bethskurrie @matt.fellows @uglyog or @tjones should be able to confirm.

phil.endsley
2020-06-16 19:56
Could be. I haven't been able to find a ton out about them. My current (maybe wrong :slightly_smiling_face: ) understanding is: Pending pacts: Don't fail provider builds if it has never been verified WIP Pacts: Update outstanding unverified pacts

robert.strauch_slack
2020-06-16 21:53
Hello all, I've just setup my first provider verification with JUnit 5 and it's basically working. I do have some trouble with the proper use of the `@State` annotation. Let's take this for example: ```@State("user already exists") public void createInactiveUser() { // logic to create user }``` The application under test already provides an endpoint to create a new user, so my first idea is using this endpoint. But how would I do this? I'm aware that the pct-jvm Maven plugin provides a state change URL parameter but it seems as if this is not available in the JUnit approach?

antonello
2020-06-16 22:02
hey @robert.strauch_slack. Inside that method annotated with your `@State` you would implement the logic to create the inactive user, for example using the endpoint that you?re referring to.

antonello
2020-06-16 22:02
that said, that state needs to be defined in the pact interaction

antonello
2020-06-16 22:03
if it is, when pact-jvm retrieves the pact and tries to run the interaction, it will run that method annotated with `@State`, provided that you?ve written your provider tests correctly.

robert.strauch_slack
2020-06-16 22:06
Sorry, my question was asked wrongly :slightly_smiling_face: I'm wondering if there is something like the `stateChangeUrl` in the Maven plugin but for the JUnit apporach. Something like an annotation like `@StateUrl("http://some-state-setup")`

robert.strauch_slack
2020-06-16 22:06
Or would the apporach be to just make a REST call with any of the available libraries?

antonello
2020-06-16 22:20
I would imagine only the latter is possible

robert.strauch_slack
2020-06-16 22:21
Thanks @antonello, that's why I was thinking as well...

antonello
2020-06-16 22:24
no problem!

phil.endsley
2020-06-16 22:30
Just curious, what rest calls are you making? One to your application that creates a user?

uglyog
2020-06-16 23:03
WIP == Pending. If your work is in progress, the pacts are marked as pending

uglyog
2020-06-16 23:06
The providerTags is needed by the broker to work out if a pact should be pending or not. The logic is that you provide the tags for your main branch (master, main, prod, whatever), and then if the broker finds a pact that does not have a verifaction result tagged with one of those, it marks it as pending.

uglyog
2020-06-16 23:07
Without that info, all pacts will be pending

phil.endsley
2020-06-17 01:11
My confusion is coming from the docs treating pending pacts and WIP pacts as two separate features. At least, that's how I keep interpreting it :confused: examples: Announcements: Pending: http://blog.pact.io/2020/02/24/how-we-have-fixed-the-biggest-problem-with-the-pact-workflow/ WIP: http://blog.pact.io/2020/02/24/introducing-wip-pacts/ CI/CD WorkShop: Pending: https://docs.pactflow.io/docs/workshops/ci-cd/workshop/protecting-the-provider/#enable-pending-pacts-for-the-provider WIP: https://docs.pactflow.io/docs/workshops/ci-cd/workshop/verifying-feature-pacts/#work-in-progress-pacts A few followup questions: 1. Are Pending Pacts flagged in Pact Broker's UI in any way, or is it just something that's tracked on the backend? 2. The jvm provider libs have support for enablePendingPacts. All other provider libs have a includeWipPactsSince parameter that gets set somewhere. This is also called out in the master issue for WIP pacts (~https://github.com/pact-foundation/pact_broker/issues/307~ oops https://github.com/pact-foundation/pact_broker/issues/338). I can't find any reference to it in the jvm libs. Is it supported? Not needed?

uglyog
2020-06-17 01:26
This is one for @bethskurrie

matt.fellows
2020-06-17 01:28
> Are Pending Pacts flagged in Pact Broker?s UI in any way, or is it just something that?s tracked on the backend? Not at the moment. It gets complicated, because the ?pending? status is not a binary yes/no - it depends on what tags it has

matt.fellows
2020-06-17 01:28
e.g. a pact can still be pending for `master` (e.g. the mainline code base) but verified for another tag e.g. `feature-x` (say, the working feature branch on the provider side)

phil.endsley
2020-06-17 01:29
> Not at the moment. It gets complicated, because the ?pending? status is not a binary yes/no - it depends on what tags it has That makes sense, because it all depends on what tag it has verified with

matt.fellows
2020-06-17 01:30
I think a better way of thinking about the differences is this: Pending pacts: don?t break the provider if it hasn?t seen a pact before WIP pacts: don?t make the provider have to guess the tags of new contracts in order to verify them. Find all of the WIP pacts and verify them (but don?t break the build)

matt.fellows
2020-06-17 01:30
I hope Beth is happy with that characterisation, because that?s how I?ve internalised it and have been communicating it

bethskurrie
2020-06-17 01:31
Yep, that's pretty accurate Matt.

matt.fellows
2020-06-17 01:31
phew

bethskurrie
2020-06-17 01:32
I'd probably say, "don't make the provider team have to manually update the list of tags to verify. Find all the pacts that are pending for this version of the provider, and automatically verify them along with the configured ones."

bethskurrie
2020-06-17 01:34
The includeWipPactSince isn't implemented in pact JVM yet, because I had forgotten that it wasn't in there, and hadn't raised the issue for Ron to do it.

bethskurrie
2020-06-17 01:34
I'll raise that today.

phil.endsley
2020-06-17 01:36
So until then, we can use pending pacts, and not break our provider builds. But we need to wait for that until we can do the WIP/second part of verifying outstanding pacts?

bethskurrie
2020-06-17 01:36
Yes.


phil.endsley
2020-06-17 01:37
Awesome. Many thanks to all of you! I think I understand it now

phil.endsley
2020-06-17 01:55
Ok, a couple more, just to make sure I really do understand :slightly_smiling_face: : Once we are able to use the WIP feature, we would want to set the providerVersionTag to whatever the current branch would be tagged as, right? We tag everything with the branch name, so for us, we would set it to `feature-x` (when on the feature-x branch) and `master` (when on the master branch). And that's so we're correctly verifying the pact on every branch is has been verified on. We can start using pending pacts today. That would be a good thing, because if a team ever merged a change with a new contract into master, the provider builds wouldn't fail. Provider can still deploy. Consumer could not (rightfully so) unless they revert it.

bethskurrie
2020-06-17 01:55
Verification results for pending pacts are published whether or not they pass or fail. They just won't fail the build.

bethskurrie
2020-06-17 01:56
> Once we are able to use the WIP feature, we would want to set the providerVersionTag to whatever the current branch would be tagged as, right?

bethskurrie
2020-06-17 01:56
Yes

bethskurrie
2020-06-17 01:56
> Consumer could not (rightfully so) unless they revert it.

bethskurrie
2020-06-17 01:57
Yes. It pushes the responsibility back on to the consumer. They need to make sure they're using can-i-deploy to ensure they don't deploy a broken contract.

bethskurrie
2020-06-17 01:58
> We tag everything with the branch name The golden rule for tagging is: Tag with the branch when you publish pacts/results, tag with the environment when you deploy.

phil.endsley
2020-06-17 01:58
Great features, btw. These were the two sources of push back we got from various teams across our company. Now, they won't have any excuses :slightly_smiling_face:

bethskurrie
2020-06-17 01:58
There is no flexible matching for key names @mbieganski.infomatt

bethskurrie
2020-06-17 01:59
It may be a feature request for the next version of the specification. Have a look at https://github.com/pact-foundation/pact-specification/issues

antonello
2020-06-17 06:18
Could all this be documented somewhere? :blush:

robert.strauch_slack
2020-06-17 07:58
@phil.endsley Exactly, at first I tried to go directly via the DAOs but as our application runs in a Java EE / CDI context there was too much overhead for me to inject the services. Do you see any "issue" in using the REST apporach?

mbieganski.infomatt
2020-06-17 10:24
Thanks:)

mbieganski.infomatt
2020-06-17 10:34
Hi. I have a service that is both Rest and amqp provider. I have 2 classes to handle each setup but problem is that now both type of consumer tests are being run by both classes so I'm ending up with error like `Only request/response interactions can be used with an HTTP test target` `java.lang.UnsupportedOperationException: Only request/response interactions can be used with an HTTP test target` I using junit5 and PactBroker. Any advice how to handle it?

phil.endsley
2020-06-17 12:39
No, not really. I was going to recommend what you were saying first, inject the DAOs directly for the setup pieces, but it looks like you already tried that. I'm not a fan of calling other parts of the system for setup for state initialization/setup, because you can get some misleading results in your tests if that's where a breaking change is made. This pact will start failing on a condition it's not responsible for. But sometimes, it is what it is, and you just have to work with what you have.

phil.endsley
2020-06-17 12:39
Also just trying to broaden my horizons and see what other strategies people are using

robert.strauch_slack
2020-06-17 13:04
Yeah, I get your point and agree. Our application is "much too heavyweight" and this causes all kind of more heavyweight stuff for testing. Maybe I'll find a more lightweight approach directly using the DAOs.

matt.fellows
2020-06-17 13:25
Beth, I love that rule. Perhaps we need to find a set of principles like the proverbs Go have: https://go-proverbs.github.io/ https://the-zen-of-go.netlify.app/

robert.strauch_slack
2020-06-17 13:47
I have a somewhat geenral question about verifying the provider side. Our application under test is kind of heavyweight, so setting up state is less than trivial. It would include a lot of different entities, database tables, etc. What's your apporach for these situations? Would you say it's fine to mock the services for the contract testing? Or would you recommend to go "all the way"?

phil.endsley
2020-06-17 14:06
We're in a similar situation. Some of our providers are giant monolithic applications that were not built with testing in mind. We're just getting to the point where we're writing Pacts for them, but our approach is going to be taking baby steps. ? Get Pacts working with mocks. Not ideal, but it's better than nothing. ? Gradually refactor so we can put more real classes into the provider verification flow ? Hopefully refactor enough that our features aren't as tightly coupled, and we can "go all the way" We know that realistically, there will be some paths that we probably won't ever get around to. But our stance is still, something is better than nothing

robert.strauch_slack
2020-06-17 19:35
@phil.endsley Do you have an example how to use Mockito in combination with Pact? My idea is to mock the injected service.

phil.endsley
2020-06-17 19:38
Nothing concrete yet, sorry. We'll hopefully have a team start on it within the next week or two. Right now, it's just our plans on paper.

robert.strauch_slack
2020-06-17 19:38
Thanks anyway. I'll ask in a channel :slightly_smiling_face:

robert.strauch_slack
2020-06-17 19:42
Hello all, I'm not sure if my apporach might be working at all... is is possible to use Mockito in combiation with JUnit 5 and Pact? The idea is to mock the specific service calls in order to avoid considering all dependencies. Does someone have a working example using Pact and Mockito?

antonello
2020-06-17 20:57
yes, you definitely can!

antonello
2020-06-17 20:59
You should be able to write your tests in the same way you?d write any other spring tests - you can choose between the HttpTarget and the MockMvc one

robert.strauch_slack
2020-06-17 21:25
@antonello Forgot to mention that the application is not based on Spring but a CDI application running within a Wildfly application server. This makes it kind of hard for me finding a meaningful approach. I've found examples for Spring but none for CDI.

antonello
2020-06-17 21:32
it should still be doable using the HttpTarget

robert.strauch_slack
2020-06-17 21:39
Do you have any examples for such a setup?

tjones
2020-06-18 00:55
For provider tests, I have found it?s generally easier to write concrete mocks rather than use a mock framework

tjones
2020-06-18 00:55
Also, if it makes sense for your case, it?s good to mock below the service layer if you can

tjones
2020-06-18 00:56
this gives some functional coverage of the service layers (Pact tests aren?t functional tests, but having some functional coverage ensures you?re testing a response your real code can actually produce)

tjones
2020-06-18 00:58
eg, if your code goes `http call ->{ controller -> service -> repository } -> SQL call to DB` , then put the cut point for the mock at `repository`

phil.endsley
2020-06-18 02:03
I'm looking for help getting pending pacts working. Everything is turned on (broker and provider), the build says it's using pending pacts, but it's still failing (1 failed test, and it's a pending one) :confused: ```com.mycompany.app.PactProviderTest > pactVerificationTestTemplate(HttpRequest, PactVerificationContext)[50] STANDARD_OUT Verifying a pact between Pact between consumerApp (079547da2e) and providerApp [PENDING] Notices: 1) The pact at [url to pact] is being verified because it matches the following configured selection criterion: latest pact for a consumer version tagged 'feature/pending-pact-tests' 2) This pact is in pending state for this version of providerApp because a successful verification result for a version of providerApp with tag 'develop' has not yet been published. If this verification fails, it will not cause the overall build to fail. Read more at https://pact.io/pending [from Pact Broker [url]] Given things exist a request to get all things returns a response which has status code 200 (OK) has a matching body (FAILED) Pending Failures: 1) Verifying a pact between consumerApp and providerApp - a request to get all things 1.1) BodyMismatch: [thing that doesn't match] ... ... > Task :app:test FAILED ... ... 336 tests completed, 1 failed FAILURE: Build failed with an exception. ... ... BUILD FAILED in 4m 34s```

uglyog
2020-06-18 02:05
Hmm, are you using the latest Pact-JVM version?

uglyog
2020-06-18 02:07
Are there any other logs? Could something else have caused the test to fail?

phil.endsley
2020-06-18 02:13
> Hmm, are you using the latest Pact-JVM version?Hmm, are you using the latest Pact-JVM version? ```testCompile("au.com.dius.pact.provider:junit5:4.1.2") testCompile("au.com.dius.pact:provider:4.1.2")``` There's logs for the other tests, but this is the only thing causing a failure. The junit report also shows this as the only failure. That shows the stack trace where it fails at at http://au.com.dius.pact.provider.junit5.PactVerificationContext.verifyInteraction(PactJUnit5VerificationProvider.kt:94) But it also has this before it, so everything looks like it should work, it's just not ```java.lang.AssertionError: Pending Failures:```

abubics
2020-06-18 02:13
In some important ways, it might depend on how the provider is layered. My usual preference is to provide stub responses from the layer just past the API endpoints (to make sure it's not just serialising/deserialising, but also validating the edge of business logic). Other people prefer to stub the services on the other end of the provider, which reduces specificity, but is often easier to inject/intercept. Always good to think about which balance you're trying to strike (some examples are listed near the end of https://medium.com/@kentbeck_7670/test-desiderata-94150638a4b3).

uglyog
2020-06-18 02:16
Oh, damn, It's not checking the pending status before throwing the exception.

uglyog
2020-06-18 02:17
I'll fix that

mbieganski.infomatt
2020-06-18 04:22
Maybe you could help @uglyog?

uglyog
2020-06-18 05:40
You need to use different consumer names, because they can't go into the same pact file

mbieganski.infomatt
2020-06-18 05:52
thanks! that's a bummer.. now wondering if or how it will impact our pipelines with webhooks

uglyog
2020-06-18 05:53
It has been raised as something to fix with V4 pact spec version

nmsuryavanshi
2020-06-18 06:46
has joined #pact-jvm

robert.strauch_slack
2020-06-18 07:13
@tjones I get your point. Setting the cut point at the repository level (that would be the DAO in our case) is a reasonable approach. But I'm not sure how to do this. I'm coming more from the tester's perspective rather than a Java developer.

robert.strauch_slack
2020-06-18 07:14
How would I "hook" that mock into the logic while running the Pact tests.

tjones
2020-06-18 07:14
Usually it?s a simple stub that implements the same interface as the repository

tjones
2020-06-18 07:15
Using whatever dependency injection framework constructs your application at startup

mbieganski.infomatt
2020-06-18 07:55
@uglyog I have to set different names for both consumer and provider right?

uglyog
2020-06-18 08:00
If you have consumer named `service1`, use that for HTTP pact test and `service1-amqp` for the message one

uglyog
2020-06-18 08:00
Provider must be the same

mbieganski.infomatt
2020-06-18 08:07
just to be clear provider also needs to be `service2` for HTTP and `service2-amqp` for AMQP.

uglyog
2020-06-18 08:09
No, you can have the provider name the same. Just change the consumer name

mbieganski.infomatt
2020-06-18 08:32
I did that and still it doesn't work. If there is more consumers for this provider tests are being run for both implementations. Unless I'm missing something in my setup..

aliihlail
2020-06-18 10:42
Help needed. :pray: Can any recommend an example for consumer test for POST method in junit5 maven.

antonello
2020-06-18 10:44
hey @aliihlail Which docs have you had a look at so far? What?s not clear specifically

aliihlail
2020-06-18 10:45
``` @Pact(consumer = "import-service", provider = "rental-service-Rest") public RequestResponsePact rentalServiceGetPact(PactDslWithProvider builder) { return builder .given("rental object with referenceId DE-01-01-02 and size 1 exist") .uponReceiving("GET request to retrieve rentals") .path(RENTAL_OBJECTS_PATH) .query("referenceId=DE-01-01-02&size=1") .method(HttpMethod.GET) .willRespondWith() .status(HttpStatus.OK.value()) .headers(responseHeaders()) .body(newJsonBody((result) -> { result.object("_embedded", (embedded) -> { embedded.minMaxArrayLike("rentalObjects", 0, 2, (rentalObjects) -> { rentalObjects.id("id"); }); }); }).getPactDslObject()) .toPact(); } @Pact(consumer = "import-service", provider = "rental-service-Rest") public RequestResponsePact rentalServicePostPact(PactDslWithProvider builder) { return builder .given("post rental from import file") .uponReceiving("POST request to import rental") .path(RENTAL_OBJECTS_BATCH_PATH) .method(http://HttpMethod.POST) .body(newJsonBody((rental) -> { rental.numberType("aggregateId"); rental.stringType("referenceId"); rental.stringMatcher("aggregateType", "UNIT|ROOM"); }).getPactDslObject()) .willRespondWith() .status(HttpStatus.OK.value()) .toPact(); } @Test @PactTestFor(pactMethod = "rentalServiceGetPact") public void testGetRentalService(MockServer mockServer) throws IOException { HttpResponse httpResponse = Request.Get(mockServer.getUrl() + RENTAL_OBJECTS_PATH + "?referenceId=DE-01-01-02&size=1").execute().returnResponse(); assertEquals(httpResponse.getStatusLine().getStatusCode(), HttpStatus.OK.value()); } @Rule private RestTemplate restTemplate = new RestTemplate(); @Test @PactTestFor(pactMethod = "rentalServicePostPact") public void testPostRentalService(MockServer mockServer) throws URISyntaxException { } private Map<String, String> responseHeaders() { Map<String, String> headers = new HashMap<>(); headers.put(CONTENT_HEADER, MediaTypes.HAL_JSON_UTF8_VALUE); return headers; } }```

aliihlail
2020-06-18 10:46
I wrote this method but im not sure how to handle ```@Test @PactTestFor(pactMethod = "rentalServicePostPact") public void testPostRentalService(MockServer mockServer) throws URISyntaxException { }```

antonello
2020-06-18 10:48
In there you need to call your actual service that will make the api request and assert something to ensure that the response that the mock server returned based on your pact is right

aliihlail
2020-06-18 11:06
```HttpResponse httpResponse = http://Request.Post(mockServer.getUrl() + RENTAL_OBJECTS_BATCH_PATH).execute().returnResponse(); assertEquals(httpResponse.getStatusLine().getStatusCode(), HttpStatus.CREATED.value());``` i tried use this but i dont belive it is right

aliihlail
2020-06-18 11:06
any recomendation ?

antonello
2020-06-18 11:07
this is not really a pact question though - it?s more about how to use clients to make post requests

mbieganski.infomatt
2020-06-18 11:21
So I found a way to solve it and don't have to change consumer name. Also looks like I have to also use 1 Context Provider where in this case I was using `PactVerificationInvocationContextProvider`and `PactVerificationSpringProvider`. For REST tests I switched to `@WebMvcTest` so now I have only one Context. In `@BeforeEach` I'm setting HTTP target and I have created `@State` for AMQP which I'm using it to set `AmpqTestTarget`. Not sure if it's best solution but working

phil.endsley
2020-06-18 12:40
Upgraded to 4.1.3 and it's working great now :tada:

satya.quote_pact
2020-06-18 14:56
I am looking for pointers/help how to use provider state change response from willrespondwith() into next uponreceiving() block. Have tried like below ```https://github.com/DiUS/pact-jvm/blob/512f683c9dd3d6659ac61f45e2a97baca18a82f7/consumer/junit5/src/test/groovy/au/com/dius/pact/consumer/junit5/ProviderStateInjectedPactTest.groovy#L33``` but not sure how to use that in uponreceiving() block any pointers much appreciated


kristine.jetzke
2020-06-18 15:02
As @antonello said, you need to call the actual service.

kristine.jetzke
2020-06-18 15:03
which will call the pact mock server (for the rest call)

kristine.jetzke
2020-06-18 15:05
In my example the test method is `userExists` which calls the `userServiceClient`(the actual service) which uses a RestTemplate. The URL of the RestTemplate gets replaced by the test to point to the pact mock server (via `user-service.base-url`property)

kristine.jetzke
2020-06-18 15:06
(This is just an example so for production-use you should need to find a way to use a random port instead of 8080. I have a Junit4 example for that https://github.com/tinexw/cdc-with-pact/blob/master/messaging-app/src/test/java/de/kreuzwerker/cdc/messagingapp/UserServiceContractTest.java but I did not yet have time to implement it for the Junit5 version)

kristine.jetzke
2020-06-18 15:11
Do you mean that for example you get `userId=100` back and then would like to another interaction where the value is used e.g. ```.uponReceiving('a request for one user') .path('/users/100')```

satya.quote_pact
2020-06-18 15:17
yes exactly, when i tried to use i always get back empty. My scenario is i need to pass 100 in the header of uponreceiving() i am doing like this ```willRespondWith() .body(new PactDslJsonBody().valueFromProviderState("id","\\${id}", "100")) .uponReceiving("another request ") .headers("xyz"," ${id}")``` but when i debug it looks ${id} is not replaced with provider state response or default value of 100

kristine.jetzke
2020-06-18 15:18
@robert.strauch_slack I have a very small example https://github.com/tinexw/cdc-with-pact/blob/master/user-service/src/test/java/de/kreuzwerker/cdc/userservice/MockedUserServiceContractTest.java that mocks out the service behind the controller. It uses spring?s `@MockBean` but can be done similarly with plain mockito. It would be the first option mentioned above > [?] to provide stub responses from the layer just past the API endpoints [?] I?m actually prefer to stub further down but it really depends on the application I would say.

kristine.jetzke
2020-06-18 15:30
:thinking_face: @uglyog?

zhukeven86
2020-06-18 18:07
has joined #pact-jvm

zhukeven86
2020-06-18 18:07
Hi. I'm planning on adding the JVM implementation of Pact (version 4.x) from the Maven Central repository, but I am unsure of which files to use. The files there seem to be fragmented and there does not seem to be a fully packaged version of JVM Pact on there. Any help would be greatly appreciated!

robert.strauch_slack
2020-06-18 18:14
Thanks @kristine.jetzke... I looked at your example and do understand your approach. I'm afarid that it won't work that simple in a CDI context? As fat I could find information it seems as if I need to spin up a "full" CDI environment with cdi-unit, Weld or else. Is that correct?

kristine.jetzke
2020-06-18 18:20
I have no experience with that :disappointed:

kristine.jetzke
2020-06-18 18:22
But maybe are there regular unit tests somewhere in the code base that already use mocks? Because the pact test is like a normal unit test so the approach should be the same

phil.endsley
2020-06-18 18:30
I'll help as much as I can... I don't know if there's an "always use this" jar out there. We just picked the one we needed for our case, and it pulled in everything else we needed. Are you adding a Consumer or Provider? Or both?

zhukeven86
2020-06-18 18:48
Im planning on providing both

zhukeven86
2020-06-18 18:49
and I'm going to set up a pact broker too

phil.endsley
2020-06-18 18:53
The repo readme has a good "what to use" section. For Consumer: https://github.com/DiUS/pact-jvm#service-consumers For Provider: https://github.com/DiUS/pact-jvm#service-providers

kristine.jetzke
2020-06-18 19:57
There is a `.headerFromProviderState` method, maybe that is what you are looking for?

kristine.jetzke
2020-06-18 20:00
```.uponReceiving('another request') .headerFromProviderState('xyz', 'id', '100')```

satya.quote_pact
2020-06-18 20:04
hmmm.. i thought if you want to get anything from header in the provider state response we should use that .headerFromProviderState.

kristine.jetzke
2020-06-18 20:05
the java doc says > Adds a header that will have it?s value injected from the provider state

kristine.jetzke
2020-06-18 20:05
I don?t fully get what you mean with > if you want to get anything from header in the provider state response

satya.quote_pact
2020-06-18 20:08
i meant if willrespondwith() returns response with headers if we want to retrieve header of the response we need to use that .headerFromProviderState. I see java docs says something different than what i thought will try with that

phil.endsley
2020-06-18 21:17
@zhukeven86 Did you get what you were looking for?

zhukeven86
2020-06-18 21:36
Yes, thanks @phil.endsley!

uglyog
2020-06-18 23:15
@satya.quote_pact Pact tests are for validating the that the individual interactions are correct according to a contract. They are tested in isolation and have no way of keeping state between tests. Seems like you are trying to do more traditional integration tests.

bethskurrie
2020-06-18 23:23
I've just added a page in http://docs.pact.io comparing Pact with other well known mocking/stubbing/contract tools. I'd like to add a section on Spring Cloud Contracts, but I've never used it. Is there anyone here who has used both, and is interested in writing a comparison? It should be as fair as possible, even calling out out what sort of situations SCC would be preferable in - we don't want to be one eyed! Here's the page https://docs.pact.io/getting_started/comparisons To contribute, just hit the EDIT button at the top, and submit a PR to the page. Ping me if you're interested. Many thanks!

aliihlail
2020-06-19 00:15
We have a scenario where we need to upload a file using post. Is there an option in pact jvm to send it in body. As i see that the bodyFile only contain file and content type.

uglyog
2020-06-19 00:16
Is it a multipart FORM POST?

aliihlail
2020-06-19 00:17
yes


uglyog
2020-06-19 00:22
You would probably need Pact-JVM 4.1.2

jess.c.ho
2020-06-19 02:25
has joined #pact-jvm

satya.quote_pact
2020-06-19 10:00
@uglyog - Well i am believe my usecase above is individual interactions only. But for doing individual interactions i need to pass header from provider state response i.e, given("provider state ") <respone of this state > into the my uponreceiving(). exactly same as here https://github.com/DiUS/pact-jvm/blob/512f683c9dd3d6659ac61f45e2a97baca18a82f7/consumer/junit5/src/test/groovy/au/com/dius/pact/consumer/junit5/ProviderStateInjectedPactTest.groovy#L23

williamfslima
2020-06-19 12:38
has joined #pact-jvm

nmsuryavanshi
2020-06-19 17:34
Hi All, one doubt, Can the pacts generated by ruby server having pact.term as part of it for matching rules(consumers) be verified by java(providers) ?

matt.fellows
2020-06-19 22:31
Yes

nouri.tawfik
2020-06-20 08:32
has joined #pact-jvm

antonello
2020-06-20 09:52
Sorry for the spam!


antonello
2020-06-20 11:53
There is more to be closed for sure. It?d be tempted to close anything that has been inactive for longer than n months

matt.fellows
2020-06-20 13:18
We use stalebot in Pact JS and it certainly helps keep things in check. Also liberal use of labels to indicate where an issue is at and how people can help

antonello
2020-06-20 13:18
Do you also have a template in pact is?

antonello
2020-06-20 13:19
Js*

matt.fellows
2020-06-21 00:09
Do you mean issue template or something else?

antonello
2020-06-21 06:57
Yes, sorry.

matt.fellows
2020-06-21 10:37
Yes we do. and examples that can be used to reproduce issues

nmsuryavanshi
2020-06-21 17:16
@matt.fellows It will be very helpful if you give any example of provider for that. I m getting an error like "Expected xxx to have value "[{"json_class":"Pact::Term", "data":{"generate"........... but was ''," Thanks

matt.fellows
2020-06-21 23:59
Please share the full error. The Ruby matchers should be fully compatible with most library versions. The Java library has the most breadth of support

matt.fellows
2020-06-21 23:59
But if I can ease your mind - one of the main benefits of pact is its multi language support

phil.endsley
2020-06-22 03:51
@uglyog /anyone else. I have a feature branch that implements this. Does this need to be discussed at all before opening a pr? My proposal would deprecate a field in the junit PactBroker annotation and replace it with a new one. This is my first foray into contributing to oss, so I figured I'd ask first before opening a pr and finding out there

uglyog
2020-06-22 03:52
Discussions would happen on the PR

uglyog
2020-06-22 03:53
Just create it and we can take it from there

nmsuryavanshi
2020-06-22 03:54
@matt.fellows here is the error Expected header 'Content-Type' to have value '{"json_class":"Pact::Term"' but was 'application/json', Expected header 'Content-Type' to have value '"data":{"generate":"application/json"' but was '', Expected header 'Content-Type' to have value '"matcher":{"json_class":"Regexp"' but was '', Expected header 'Content-Type' to have value '"o":0' but was '', Expected header 'Content-Type' to have value '"s":"application\/json"}}}' but was ''

aliihlail
2020-06-22 10:51
``` @Pact(consumer = "import-service", provider = "rental-service-Rest") public RequestResponsePact rentalServiceGetPact(PactDslWithProvider builder) { return builder .given("rental object with referenceId DE-01-01-02 and size 1 exist") .uponReceiving("GET request to retrieve rentals") .path(RENTAL_OBJECTS_PATH) .query("referenceId=DE-01-01-02&size=1") .method(HttpMethod.GET) .willRespondWith() .status(HttpStatus.OK.value()) .headers(responseHeaders()) .body(newJsonBody((result) -> { result.object("_embedded", (embedded) -> { embedded.minMaxArrayLike("rentalObjects", 0, 2, (rentalObjects) -> { rentalObjects.id("id"); }); }); }).getPactDslObject()) .toPact(); } @Pact(consumer = "import-service", provider = "rental-service-Rest") public RequestResponsePact rentalServicePostPact(PactDslWithProvider builder) throws IOException { return builder .given("post rental from import file") .uponReceiving("POST request to import rental") .path(RENTAL_OBJECTS_BATCH_PATH) .method(http://HttpMethod.POST) .body(newJsonBody((rental) -> { rental.numberType("aggregateId"); rental.stringType("referenceId"); rental.stringMatcher("aggregateType", "UNIT|ROOM"); }).getPactDslObject()) .withFileUpload("file", "file", "multipart/form-data", "aggregateId,aggregateType,amenityId".getBytes()) .willRespondWith() .status(HttpStatus.CREATED.value()) .toPact(); } @Test @PactTestFor(pactMethod = "rentalServiceGetPact") public void testGetRentalService(MockServer mockServer) throws IOException { HttpResponse httpResponse = Request.Get(mockServer.getUrl() + RENTAL_OBJECTS_PATH + "?referenceId=DE-01-01-02&size=1").execute().returnResponse(); assertEquals(httpResponse.getStatusLine().getStatusCode(), HttpStatus.OK.value()); } @Test @PactTestFor(pactMethod = "rentalServicePostPact") public void testPostRentalService(MockServer mockServer) throws Exception { String body = "{\"aggregateId\": 100, \"referenceId\": \"DE-01-001-01\", \"aggregateType\": \"UNIT\"}"; HttpEntity data = MultipartEntityBuilder.create() .setMode(HttpMultipartMode.BROWSER_COMPATIBLE) .addBinaryBody("file", "aggregateId,aggregateType,amenityId".getBytes()) .build(); HttpResponse httpResponse = http://Request.Post(mockServer.getUrl() + RENTAL_OBJECTS_BATCH_PATH) .bodyString(body, ContentType.MULTIPART_FORM_DATA) .body(data).execute().returnResponse(); assertEquals(httpResponse.getStatusLine().getStatusCode(), HttpStatus.CREATED.value()); } private Map<String, String> responseHeaders() { Map<String, String> headers = new HashMap<>(); headers.put(CONTENT_HEADER, MediaTypes.HAL_JSON_UTF8_VALUE); return headers; } }``` Hi Im getting an error when im trying to test the rentalServicePostPact any hellp how to do it. I would appreciate it if any one helped me...

antonello
2020-06-22 10:52
Telling us what error you?re getting would help us :slightly_smiling_face:

aliihlail
2020-06-22 10:53
path: /rental-objects/batch query: {} headers: {Accept-encoding=[gzip,deflate], Connection=[Keep-Alive], Host=[localhost:33325], User-agent=[Apache-HttpClient/4.5.6 (Java/11.0.1)], Content-type=[multipart/form-data; boundary=0Tj2WYylWt0ZsDhKjKEFVfQjrvRrdD1RSeH], Content-length=[164]} matchers: MatchingRules(rules={}) generators: Generators(categories={}) body: PRESENT(--0Tj2WYylWt0ZsDhKjKEFVfQjrvRrdD1RSeH Content-Disposition: form-data; name="file" aggregateId,aggregateType,amenityId --0Tj2WYylWt0ZsDhKjKEFVfQjrvRrdD1RSeH-- ) 11:24:33.995 [HTTP-Dispatcher] DEBUG http://au.com.dius.pact.core.matchers.RequestMatching - comparing to expected request: method: POST path: /rental-objects/batch query: {} headers: {Content-Type=[multipart/form-data; boundary=Sd9x3en73qCRHCLgd7d6Ltzy9dGPoVJ5FmEkQ9_9]} matchers: MatchingRules(rules={body=Category(name=body, matchingRules={$.aggregateId=MatchingRuleGroup(rules=[NumberTypeMatcher(numberType=NUMBER)], ruleLogic=AND), $.referenceId=MatchingRuleGroup(rules=[http://au.com.dius.pact.core.model.matchingrules.TypeMatcher@4446726c], ruleLogic=AND), $.aggregateType=MatchingRuleGroup(rules=[RegexMatcher(regex=UNIT|ROOM, example=null)], ruleLogic=AND)}), header=Category(name=header, matchingRules={Content-Type=MatchingRuleGroup(rules=[RegexMatcher(regex=multipart/form-data;(\s*charset=[^;]*;)?\s*boundary=.*, example=multipart/form-data; boundary=Sd9x3en73qCRHCLgd7d6Ltzy9dGPoVJ5FmEkQ9_9)], ruleLogic=AND)})}) generators: Generators(categories={BODY={$.aggregateId=RandomIntGenerator(min=0, max=2147483647), $.referenceId=RandomStringGenerator(size=20), $.aggregateType=RegexGenerator(regex=UNIT|ROOM)}}) body: PRESENT(--Sd9x3en73qCRHCLgd7d6Ltzy9dGPoVJ5FmEkQ9_9 Content-Disposition: form-data; name="file"; filename="file" Content-Type: multipart/form-data aggregateId,aggregateType,amenityId --Sd9x3en73qCRHCLgd7d6Ltzy9dGPoVJ5FmEkQ9_9-- ) 11:24:34.003 [HTTP-Dispatcher] DEBUG http://au.com.dius.pact.core.matchers.HeaderMatcher - Comparing header 'Content-Type': 'multipart/form-data; boundary=0Tj2WYylWt0ZsDhKjKEFVfQjrvRrdD1RSeH' to 'multipart/form-data; boundary=Sd9x3en73qCRHCLgd7d6Ltzy9dGPoVJ5FmEkQ9_9' 11:24:34.010 [HTTP-Dispatcher] DEBUG http://au.com.dius.pact.core.matchers.MatcherExecutor - comparing 'multipart/form-data; boundary=0Tj2WYylWt0ZsDhKjKEFVfQjrvRrdD1RSeH' with regexp multipart/form-data;(\s*charset=[^;]*;)?\s*boundary=.* at [Content-Type] -> true 11:24:34.450 [HTTP-Dispatcher] DEBUG http://au.com.dius.pact.core.matchers.Matching - Found a matcher for multipart/form-data -> http://au.com.dius.pact.core.matchers.MultipartMessageBodyMatcher@13dc4dd2 11:24:34.521 [HTTP-Dispatcher] ERROR http://au.com.dius.pact.consumer.BaseJdkMockServer - Failed to generate response javax.mail.MessagingException: Missing start boundary

antonello
2020-06-22 10:57
could you format it please?

aliihlail
2020-06-22 10:59
ERROR http://au.com.dius.pact.consumer.BaseJdkMockServer - Failed to generate response javax.mail.MessagingException: Missing start boundary

aliihlail
2020-06-22 10:59
here is the error

aliihlail
2020-06-22 11:03
the idea that i trying to test the post with multipart FORM POST and it is a bit complicated. If any one helped it would be amzing

dattasai.chunduru
2020-06-22 12:48
has joined #pact-jvm

dattasai.chunduru
2020-06-22 12:50
Hi Can anyone help me in doing a POST request by using PACT this is my code snippet.

dattasai.chunduru
2020-06-22 12:52
it is showing me error

dattasai.chunduru
2020-06-22 12:52
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 8.793 sec <<< FAILURE! testPact(pact_post.pact_post.PactBaseConsumerTest) Time elapsed: 2.54 sec <<< FAILURE! java.lang.AssertionError: Pact Test function failed with an exception, possibly due to Mismatches(mismatches=[UnexpectedRequest(request= method: GET path: /comments query: {} headers: {Accept=[application/json, application/*+json], Connection=[keep-alive], Host=[kubernetes.docker.internal:54925], User-agent=[Java/14.0.1]} matchers: MatchingRules(rules={}) generators: Generators(categories={}) body: EMPTY)]) at http://au.com.dius.pact.consumer.junit.ConsumerPactTest.testPact(ConsumerPactTest.java:41) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74) at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) Caused by: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Internal Server Error: [{ "error": "Unexpected request : \tmethod: GET\n\tpath: \/comments\n\tquery: {}\n\theaders: {Accept=[application\/json, application\/*+json], Connection=[keep-alive], Host=[kubernetes.docker.internal:54925], User-agent=[Java\/14.0.1]}\n\tmatchers: MatchingRules(rules={})\n\tgenerators: Generators(categories={})\n\tbody: EMPTY" }] at org.springframework.web.client.HttpServerErrorException.create(HttpServerErrorException.java:100) at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:172) at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:112) at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63) at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:782) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:740) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:674) at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:315) at pact_post.pact_post.ProviderService.getInformation(ProviderService.java:20) at pact_post.pact_post.PactBaseConsumerTest.runTest(PactBaseConsumerTest.java:54) at http://au.com.dius.pact.consumer.junit.ConsumerPactTest.lambda$testPact$0(ConsumerPactTest.java:32) at http://au.com.dius.pact.consumer.BaseMockServer.runAndWritePact(MockHttpServer.kt:110) at http://au.com.dius.pact.consumer.ConsumerPactRunnerKt.runConsumerTest(ConsumerPactRunner.kt:13) at http://au.com.dius.pact.consumer.junit.ConsumerPactTest.testPact(ConsumerPactTest.java:31) ... 38 more 2020-06-22 18:21:40.530 INFO 11840 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor' Results : Failed tests: testPact(pact_post.pact_post.PactBaseConsumerTest): Pact Test function failed with an exception, possibly due to Mismatches(mismatches=[UnexpectedRequest(request= method: GET(..) Tests run: 1, Failures: 1, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 49.969 s [INFO] Finished at: 2020-06-22T18:21:40+05:30 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project pact-post: There are test failures. [ERROR] [ERROR] Please refer to C:\Users\dattasai.sukumar\Documents\workspace\pact-post\target\surefire-reports for the individual test results. [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

dattasai.chunduru
2020-06-22 13:22
I tried removing the body formating and send it as normal body but still it is failing

dattasai.chunduru
2020-06-22 13:22
@RunWith(SpringRunner.class) @SpringBootTest public class PactBaseConsumerTest extends ConsumerPactTest{ @Autowired ProviderService providerService; @Override @Pact(provider="ProviderJson", consumer="ConsumerJson") public RequestResponsePact createPact(PactDslWithProvider builder) { Map<String, String> headers = new HashMap<String, String>(); headers.put("Content-Type", "application/json;charset=utf-8"); return builder .given("example verification") .uponReceiving("request verification") .method("POST") .headers(headers) .body("{ \"id\": 3,\"name\": \"postcomments\", \"postId\": 3 }") .path("/comments") .willRespondWith() .status(201) .toPact(); } @Override protected String providerName() { return "ProviderJson"; } @Override protected String consumerName() { return "ConsumerJson"; } @Override protected void runTest(MockServer mockServer, PactTestExecutionContext context) { providerService.setBackendURL(mockServer.getUrl()); Information information = providerService.getInformation(); //assertEquals(information.getTitle(),"sunt aut facere repellat provident occaecati excepturi optio reprehenderit"); } }

dattasai.chunduru
2020-06-22 13:23
I have used https://github.com/Mikuu/Pact-JVM-Example/tree/master/example-consumer-miku this GITHUB and build my code for Consumer side POST method

dattasai.chunduru
2020-06-22 13:25
Hi All

dattasai.chunduru
2020-06-22 13:25
If anyone can help me with POST METHOD CODE snippet I will be really Thankful

phil.endsley
2020-06-22 13:32
I thought I replied, but I don't see it anywhere. Guess it got lost :shrug: Based on the error, it looks like your test is making a GET call, but your pact is expecting a POST. I would double check the code in here to make sure it's making a POST call ```Information information = providerService.getInformation();```

dattasai.chunduru
2020-06-22 13:40
Hi Phil

dattasai.chunduru
2020-06-22 13:40
I am using ProviderSerivce class like this

phil.endsley
2020-06-22 13:44
```restTemplate.getForObject(getBackendURL(), Information.class);``` This is making a GET call. You would need to change this to make a POST. ex: `restTemplate.postForObject` or however you want to make the call. The test is correctly failing, since your consumer's behavior does not match what the pact is defining.

dattasai.chunduru
2020-06-22 14:19
Actually I tried with postFor Location it is not working

dattasai.chunduru
2020-06-22 14:19
I did not find postforObject I will check this Thank you Phil :slightly_smiling_face:

antonello
2020-06-22 14:51
@dattasai.chunduru I?d recommend that you create one clear message, format your code properly, and keep all your messages in one thread.

wesleythomaswilliams
2020-06-22 14:56
@antonello I wish slack would automatically convert long messages into snippets.

dattasai.chunduru
2020-06-22 18:42
Hi All , Can anyone please share Code snippets for PACT POST method. I am not able to get any GITHUB examples for POST method

dattasai.chunduru
2020-06-22 18:55
I am getting URI not absolute error can anyone please help me on this

dattasai.chunduru
2020-06-22 18:56
this is my code snipper

phil.endsley
2020-06-22 19:14
What's the uri you're trying to call? From the snippet below, are you missing the `@Rule` annotation for `mockProvider`

phil.endsley
2020-06-22 19:18
As for not being able to get any POST contracts working, have you been able to get any working (ex: GET)? It's all pretty much the same from the Pact side

phil.endsley
2020-06-22 19:20
If you're looking for a tutorial, there's a jvm workshop that's linked in the pact-jvm repo. https://github.com/DiUS/pact-workshop-jvm It walks through an example for a GET request. But like I said, once you get one of them working, it's all pretty much the same for the other verbs

dattasai.chunduru
2020-06-22 20:24
I have working code for PACT-GET method. I did both Consumer and provider side and the verification in PACT broker is also done

dattasai.chunduru
2020-06-22 20:25
I started with POST and in restTemplate.PostForObject I am not able to give proper parameters

dattasai.chunduru
2020-06-22 20:27
I tried with resttemplate.exchange also when using this I am getting URI not absolate error

dattasai.chunduru
2020-06-22 20:49
Ohh I missed @rule yes thank you @phil.endsley

aliihlail
2020-06-22 22:23
Again im trying to test a post with mutltipart file Post. I wrote this simple test. Here is the code ```@Pact(consumer = "import-service", provider = "feature-service") public RequestResponsePact featureServicePostPact(PactDslWithProvider builder) throws IOException { return builder .given("post feature from import file") .uponReceiving("POST request to import feature") .path(FEATURES_IMPORT_PATH) .method(http://HttpMethod.POST) .withFileUpload("file", "data.csv", "multipart/form-data", "aggregateId,aggregateType,amenityId".getBytes()) .willRespondWith() .body("every thing is okay") .status(HttpStatus.CREATED.value()) .toPact(); } @Test @PactTestFor(pactMethod = "featureServicePostPact") public void testPostFeatureService(MockServer mockServer) throws IOException { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpEntity data = MultipartEntityBuilder.create() .setMode(HttpMultipartMode.BROWSER_COMPATIBLE) .addBinaryBody("file", "aggregateId,aggregateType,amenityId".getBytes(), ContentType.MULTIPART_FORM_DATA, "data.csv") .build(); HttpUriRequest request = RequestBuilder .post(mockServer.getUrl() + FEATURES_IMPORT_PATH) .setEntity(data) .build(); httpclient.execute(request); }``` Unfortinattly im getting the following error: http://au.com.dius.pact.consumer.PactMismatchesException: The following requests were not received: method: POST path: /features/import query: {} headers: {Content-Type=[multipart/form-data; boundary=QpUt6W_VwiazcsGsTjIZhx36U2USKZNzCcN-J2BX]} matchers: MatchingRules(rules={header=Category(name=header, matchingRules={Content-Type=MatchingRuleGroup(rules=[RegexMatcher(regex=multipart/form-data;(\s*charset=[^;]*;)?\s*boundary=.*, example=multipart/form-data; boundary=QpUt6W_VwiazcsGsTjIZhx36U2USKZNzCcN-J2BX)], ruleLogic=AND)}), path=Category(name=path, matchingRules={})}) generators: Generators(categories={}) body: PRESENT(--QpUt6W_VwiazcsGsTjIZhx36U2USKZNzCcN-J2BX Content-Disposition: form-data; name="file"; filename="data.csv" Content-Type: multipart/form-data aggregateId,aggregateType,amenityId --QpUt6W_VwiazcsGsTjIZhx36U2USKZNzCcN-J2BX-- )

uglyog
2020-06-22 23:15
Are you able to provide debug logs to see why it is not matching?

uglyog
2020-06-22 23:16
The only thing I can see that is wrong, is you specified `"multipart/form-data"` as the file content type, when I think it should be `text/csv`

artur.ashyrov
2020-06-23 06:53
has joined #pact-jvm

antonello
2020-06-23 09:46
Does anyone know how to change the log level to get some more verbose logging?

chandanakurumeti27
2020-06-23 10:47
Hi, is it possible to send post request inside the provider states in pact jvm?

chandanakurumeti27
2020-06-23 10:51
My issue is , am basically about to run provider tests for ,lets say , `getgames` request , i need to have some games in first place to get them. so am planning to have `savegame` request inside the provider state so some games exists in DB to retrieve them while running provider tests.

chandanakurumeti27
2020-06-23 10:52
Any help would be much appreciated!

matt.fellows
2020-06-23 10:56
Provider states are just functions that execute when the state needs to be setup. You can do whatever you need in them. I would try to make things faster though, so dealing with on memory database objects tends to be simpler and more performant

aliihlail
2020-06-23 11:40
i changed it and i got the same error Do i need to add the Pact JVM 4,.1.4 dependency.

satya.quote_pact
2020-06-23 12:37
Hi just wondering if this use case is possible in pact-jvm. 1. In given("statechange"). --> save the response of given () 2. And use response of 1 in the uponreceiving() 3. And perform the interaction

matt.fellows
2020-06-23 12:49
Are you asking if it?s possible to persist data from a state change for use when the interaction is called during provider verification?

matt.fellows
2020-06-23 12:49
What do you want to do?

satya.quote_pact
2020-06-23 13:12
yes, basically for each interaction we do we need to have token. We have state change for getting s2s setup as a part of given(). but we need to use that in the header of the uponreceiving() for testing the contract

matt.fellows
2020-06-23 13:46
Have a look at request filters

chandanakurumeti27
2020-06-23 14:50
Thank you :slightly_smiling_face:

rafael.espillaque
2020-06-23 15:07
hi all, I?m having a problem when trying to migrate from 4.0.10 to 4.1.4. 4.1.4 says: `java.lang.UnsupportedOperationException: At least one pact source must be present on the test class` I believe it?s related to my `@PactFolder` annotation not being read. I?m using the following annotations at class level: ```@SpringBootTest @Provider("my-project") @PactFolder("../pacts") @IgnoreNoPactsToVerify``` any ideas? thanks

aliihlail
2020-06-23 15:08
I have the same issue

phil.endsley
2020-06-23 15:25
Double check your imports and make sure you're using `http://au.com.dius.pact.provider.junitsupport.loader.PactFolder`

rafael.espillaque
2020-06-23 15:26
wow good catch! that?s it. I was using ```au.com.dius.pact.core.model.annotations.PactFolder;```

rafael.espillaque
2020-06-23 15:26
thanks a lot

francislainy.campos
2020-06-23 15:36
.

francislainy.campos
2020-06-23 15:37
.

rafael.espillaque
2020-06-23 18:54
Pending pacts and WIP pacts seem a very useful feature. How well supported are them from jvm libraries?



antonello
2020-06-23 19:47
(the whole thread)


uglyog
2020-06-23 22:59
Depends. With Gradle, Maven or JUnit?

uglyog
2020-06-23 23:24
I'm going to rename those annotations, because those are totally confusing

antonello
2020-06-23 23:59
Junit and maven

matt.fellows
2020-06-24 00:02
It looks like your pact generation is broken. Can you please share the contract that was generated?

uglyog
2020-06-24 00:04
With JUnit, you have it set on the test JVM. Easiest way is to add logback to the test classpath. It should configure DEBUG level by default.

uglyog
2020-06-24 00:05
For other levels, you need to add a logback configuration file to the test resources.

uglyog
2020-06-24 00:06
For Maven (i.e. the Maven pact plugin, not running tests with Maven), the -X command line argument will do it.

mbieganski.infomatt
2020-06-24 04:59
Hi. I have a case when there is no contract on master branch yet and when I merge provider will throw error `".NoPactsFoundException at PactJUnit5VerificationProvider".` There is an option to use `@IgnoreNoPactsToVerify` but wondering if it's good practice to use it in CI, is it expected Pact behaviour for provider to pass when there is no pacts or it should be handeled differently? @uglyog, @bethskurrie what do you think? Thanks

uglyog
2020-06-24 05:07
That is what that annotation is for. Just remember to remove it once you have pacts published.

gerrelatanacio
2020-06-24 07:02
has joined #pact-jvm

mbieganski.infomatt
2020-06-24 07:57
So there is no way to do it fully "automatically". For a second I thought to include `latest` like tags = {"latest", "dev", "prod"} but I think it's not really recommended?

rafael.espillaque
2020-06-24 08:45
thanks you both!

d.duraivelan
2020-06-24 09:00
has joined #pact-jvm

antonello
2020-06-24 09:58
Thank you!

chandanakurumeti27
2020-06-24 10:57
Hi, Can i access request body inside statechange method, as i want to use one of the request field values inside statechange

chandanakurumeti27
2020-06-24 10:57
Is it possible?

chandanakurumeti27
2020-06-24 10:59
lets say, my request body in the contract is {?consumerid? = ?462"} and i want to get the orders for this customer from the order service which inturn talks to DB. so am planning to add some random order for this consumer ?462? in DB inside statechange method

chandanakurumeti27
2020-06-24 10:59
so I want to get that consumerid into statechange method from the requestbody

chandanakurumeti27
2020-06-24 11:00
How can i do that?, kindly help me on this. Looking forward to any kind of help.thanks

francislainy.campos
2020-06-24 11:42
Hi, I'm getting this error when trying to run my provider tests please. `org.junit.runners.model.InitializationError` `at http://au.com.dius.pact.provider.junit.PactRunner.initialize(PactRunner.kt:112)` `at http://au.com.dius.pact.provider.junit.PactRunner.getChildren(PactRunner.kt:140)`

francislainy.campos
2020-06-24 11:42
This is my full pom.

francislainy.campos
2020-06-24 11:43
```<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.hmhco</groupId> <artifactId>tests</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <properties> <java.version>1.8</java.version> <maven.compiler.version>3.8.1</maven.compiler.version> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <rest-assured.version>3.0.0</rest-assured.version> <json-schema-validator.version>3.3.0</json-schema-validator.version> </properties> <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.5.2</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-consumer-junit5</artifactId> <version>4.0.10</version> </dependency> <dependency> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-provider-junit</artifactId> <version>4.0.10</version> </dependency> <dependency> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-provider-junit5</artifactId> <version>4.0.10</version> <scope>test</scope> </dependency> <dependency> <groupId>io.rest-assured</groupId> <artifactId>rest-assured</artifactId> <version>${rest-assured.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>io.rest-assured</groupId> <artifactId>json-schema-validator</artifactId> <version>${json-schema-validator.version}</version> <scope>test</scope> </dependency> <!-- As per https://stackoverflow.com/a/52872160/6654475 --> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.3.1</version> </dependency> <dependency> <groupId>org.glassfish.jaxb</groupId> <artifactId>jaxb-runtime</artifactId> <version>2.3.1</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.7.30</version> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M4</version> <!--- This is creating conflicts between junit 4 and 5 --> <dependencies> <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-surefire-provider</artifactId> <version>1.2.0</version> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.2.0</version> </dependency> </dependencies> </plugin> <plugin> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>4.0.10</version> <configuration> <pactDirectory>target/pacts</pactDirectory> <pactBrokerUrl>http://pact-broker-hmh.devel.hmheng-qe.brnp.internal/</pactBrokerUrl> <projectVersion>${project.version}</projectVersion> <trimSnapshot>true</trimSnapshot> </configuration> </plugin> </plugins> </build> </project>```

chandanakurumeti27
2020-06-24 11:43
Can i get some link where i could find any example

chandanakurumeti27
2020-06-24 11:43
and i think valueFromProviderState method helps me in this case.

francislainy.campos
2020-06-24 11:43
Thank you.



chandanakurumeti27
2020-06-24 13:37
Yeah it did help me. Thanks @phil.endsley :+1:

matt.fellows
2020-06-24 13:49
Thanks for all of your recent help here @phil.endsley, loving waking up and see all of these responses!

phil.endsley
2020-06-24 14:10
My pleasure! I'm just happy I can give back to the project

phil.endsley
2020-06-24 15:13
On the 4.x branch, that stacktrace points to a line indicating no pacts were found for the specified provider. https://github.com/DiUS/pact-jvm/blob/v4.x/provider/pact-jvm-provider-junit/src/main/kotlin/au/com/dius/pact/provider/junit/PactRunner.kt#L112

hadjaliabir
2020-06-24 16:09
has joined #pact-jvm

antonello
2020-06-24 22:05
@phil.endsley - Do you think it would be worth adding something to readmes to document your consumerVersionSelectors feature? https://github.com/DiUS/pact-jvm/pull/1143/

phil.endsley
2020-06-24 22:08
Yes. I was actually thinking the same thing today

antonello
2020-06-24 22:12
We had a conversation on the functionality at Treatwell today as one of the native apps team wanted just that

antonello
2020-06-24 22:15
Do you need it released by the way?

antonello
2020-06-24 22:16
For their specific use case I also mentioned to them an alternative approach - tag every release with a unique release number and then whitelist the versions/releases that the provider needs to verify.

phil.endsley
2020-06-24 22:20
For releasing, I have a branch I'm working on for wip pacts. They can be released independently though

antonello
2020-06-24 22:24
Let me know - I?m sure we can do a patch release.

uglyog
2020-06-24 23:04
You can provide parameters to the state change when it is defined in the consumer test. These parameters will be passed to the state change method when verifying the provider.

uglyog
2020-06-24 23:06
BTW, @bethskurrie has done some loverly work and all the readmes now also appear on http://docs.pact.io

uglyog
2020-06-24 23:15
latest is normally used to fetch the latest pact for a tag. It becomes confusing if you use it as a tag as well.

bethskurrie
2020-06-24 23:16
I've been thinking of disallowing this as a tag!

bethskurrie
2020-06-24 23:16
I think the jvm api is confusing by calling the tag "latest" personally.

antonello
2020-06-25 06:14
:clap::skin-tone-2:

francislainy.campos
2020-06-25 08:13
Thank you Phil. I wasn't being able to fix this so changed the file to use JUnit5 instead and it's working now. Cheers.

bethskurrie
2020-06-25 22:52
All the Pact JVM docs are now synced to http://docs.pact.io and have been indexed by our wonderful free-for-OSS search engine Algolia. This should make things much easier to find. Remember to do a search at http://docs.pact.io before you ask a question here - you just might find the answer yourself now :wink: I know it can often be tricky to get all the maven stuff working with the annotations - if you have a working example, I'd love to add one to the docs. Please let me know!

bethskurrie
2020-06-26 01:51
@antonello @phil.endsley I'm going to add a specific section for consumer version selectors here: https://pact.io/selectors

bethskurrie
2020-06-26 01:52
I'd prefer to have the docs all in one place, so the JVM ones can explain the technical bits, and then point to the generic docs for understanding the functionality.

phil.endsley
2020-06-26 02:00
I like that idea :+1:

phil.endsley
2020-06-26 03:24
@antonello /(anyone else?), I'm good with a release now. Not really sure how that process works/what governs it.

uglyog
2020-06-26 03:24
I could do a release this weekend

srinivasan.sekar1990
2020-06-26 05:03
Thanks alot for sharing @bethskurrie Here is an example on jvm - https://github.com/SrinivasanTarget/ContractTestingBoilerplate

nmsuryavanshi
2020-06-26 05:50
Hi All, can anyone please suggest how can we write provider test for 400 bad request(missing field(@NotNull) value in dto) in java. Thanks.

uglyog
2020-06-26 05:53
It's pretty much the same as any other Pact test. You have an example in the consumer test that will make a request that will generate the response, and set the expected response as 400

nmsuryavanshi
2020-06-26 05:56
Can we also check error message in provider test or only we can verify status?

uglyog
2020-06-26 06:01
You can verify the error message if it is returned in the body, which with Spring it will be

nmsuryavanshi
2020-06-26 06:41
In provider test we set the controller as target and we mock the service implementation and use when(service.something()).then return(). So how do I test the 400 bad request in provider test?

nmsuryavanshi
2020-06-26 06:43
for successfull scenarios we do when().thenReturn() beacuse we use @Mock for service. But how can i do it for 400 badrequest as it will not be thrown from service its in dto validation through annotations like @NotNull

bethskurrie
2020-06-26 08:23
Awesome! Thanks @srinivasan.sekar1990

ashish_garg5
2020-06-26 10:57
Hi All, Is there any way to check if consumer is there in my pact broker or not ? Or any api to get the consumer names from the pact broker ? Thanks in advance.

nmsuryavanshi
2020-06-26 11:03
@uglyog can you give any example please for checking 400 badrequest thrown for @NotNull annotation

antonello
2020-06-26 11:04
you can check if there is a pacticipant `/pacticipants/{pacticipant}`

ashish_garg5
2020-06-26 11:10
ok thanks but if it is not there then i am getting 4040

ashish_garg5
2020-06-26 11:10
404

matt.fellows
2020-06-26 11:11
The pact broker is entirely API driven and very RESTful. If you query the root resource at / you can follow links to anything you need. There is also a HAL browser in the UI you can use to explore the API

antonello
2020-06-26 11:12
Yes, getting a 404 is expected if the pacticipant doesn?t exist

ashish_garg5
2020-06-26 11:14
sure thanks

phil.endsley
2020-06-26 13:16
@nmsuryavanshi If your controller is taking action based on an exception thrown from the service layer, you would need to setup your mock to throw the expected exception. `when(service.something()).thenThrow(...)`

nmsuryavanshi
2020-06-26 15:12
@phil.endsley Yes that can be done but the thing is when the request is received in endpoint @Valid annotation is written so the call doesn't go to service layer.

phil.endsley
2020-06-26 17:18
Ah...I misunderstood. I guess I don't fully understand the issue. If the validation is happening by the framework at the controller level, before it hits any of your controller code, wouldn't this "just work"? Either that, or there's a piece of the application (maybe at the framework level) not being stood that your provider would normally have when deployed?

phil.endsley
2020-06-26 17:20
I don't have experience with those specific annotations, but I don't think that implementation detail really matters in trying to understand the issue. There's some component that runs validation somewhere. That either needs to be mocked out like your service layer, or stood up with your controller.

phil.endsley
2020-06-26 17:20
If that's not the case, I think you'll have to wait for someone else to chime in

nmsuryavanshi
2020-06-26 17:47
I tried using mockmvc but it didnt worked.

phil.endsley
2020-06-26 17:59
Are you using spring boot?

phil.endsley
2020-06-26 18:09
I did a quick and dirty test for one of our Spring Boot projects (Added `@Valid` to the controller, and `@NotNull` to an entity property, and it looks like it's working like I would expect ```MockHttpServletResponse response = mockMvc.perform(post(url) .contentType(MediaType.APPLICATION_JSON) .content(toJson(body)) .headers(headers)) .andReturn() .getResponse(); assertThat(HttpStatus.resolve(response.getStatus())).isEqualTo(HttpStatus.CREATED);``` > org.opentest4j.AssertionFailedError: > Expecting: > <400 BAD_REQUEST> > to be equal to: > <201 CREATED> > but was not. > Expected :201 CREATED > Actual :400 BAD_REQUEST

phil.endsley
2020-06-26 18:10
And to clarify, this doesn't seem like an issue with Pact, rather getting the framework you're using to behave as you expect

kristine.jetzke
2020-06-26 21:01
I agree, it?s a spring boot question. > when the request is received in endpoint @Valid annotation is written so the call doesn?t go to service layer. It does not need to because the framework will return a 400 because of the `@Valid` annotation. Obviously the payload you?re passing must not be valid. But with `MockMvc` you don?t get the actual JSON response, you just get the http://org.springframework.web.bind.MethodArgumentNotValidException. In theory you could manually add the https://github.com/spring-projects/spring-boot/blob/2.3.x/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorController.java but I would recommend to use a ?real? spring boot integration test i.e. one that loads the complete web application instead. Because one important aspect of the contract test it to test the actual format of the response. There are so many places in spring boot where this can be configured which is why I would load the complete application.

phil.endsley
2020-06-26 21:19
> But with `MockMvc` you don?t get the actual JSON response, you just get the https://slack-redir.net/link?url=http%3A%2F%2Forg.springframework.web.bind.MethodArgumentNotValidException. Didn't realize this. Maybe that's why it wasn't working for @nmsuryavanshi if they were trying to assert specific properties aside from status code? > I would recommend to use a ?real? spring boot integration test i.e. one that loads the complete web application instead. This is what we do, and it works great

uglyog
2020-06-27 02:03
@phil.endsley 4.1.5 is released

ag.robinson
2020-06-27 15:41
has joined #pact-jvm

nmsuryavanshi
2020-06-29 04:34
Hi @phil.endsley can you please show me what all class level annotation you used during test that you written above . Thanks

andreas
2020-06-29 08:49
@bethskurrie This is great! Consider pinning this post, or make a post for about "not asking before you have searched" kind of post that you can pin to the channel?

naree.song
2020-06-29 09:12
has joined #pact-jvm

phil.endsley
2020-06-29 13:14
```@Provider("providerApp") @PactBroker( host = "pactbrokerhost", scheme = "https", tags = "develop" ) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ExtendWith(SpringExtension.class) @ActiveProfiles("test") class ProviderAppPactProviderTest {``` We're using Spring Boot with junit 5 Our consumer/provider are not in prod yet, so we're only verifying against our develop tag. Once we go to prod, we'll update our tags to verify against that too.

r.iglesias
2020-06-30 06:26
Hello people. I have a couple of questions regarding some last features added since version 4.1.X ? Is the pending pacts feature also supported in the `pact-broker-docker` ? I read in some doc that this only available through the hosted version with `http://pacflow.io` ? Same for the consumer version selectors. We are interested in verifying contracts where the consumer is a mobile app, and here several versions could be tagged as `prod` Thanks in advance!


matt.fellows
2020-06-30 06:43
you need to explictly enable it

r.iglesias
2020-06-30 06:57
you mean this `PACT_BROKER_FEATURES=pacts_for_verification` right? and does this allow both WIP and pending pacts?

matt.fellows
2020-06-30 07:02
yes I believe so

r.iglesias
2020-06-30 07:03
Cool thanks!

gauravsingh1095
2020-06-30 07:22
has joined #pact-jvm

gauravsingh1095
2020-06-30 07:26
Hi team, need some help, I facing an issue while verifying contract on Provider side Scenario: My consumer is a React app, Providers are Spring-boot microservices Now while verifying the Contract, Microservice A requires cookies in the header which I inject using `@TestTemplate` . Internally microservice A calls microservice B using FeignClient to verify the session. I am not able to mock microservice B while verifying Provider A. Tried mockito to mock but it didnt work. :persevere: Please help!!!

sairsule
2020-06-30 07:27
what is the issue

gauravsingh1095
2020-06-30 08:02
Or can you point me to any docs related to this?

sairsule
2020-06-30 08:02
please post your code snippet. are u using Junit 5?

gauravsingh1095
2020-06-30 08:03
yes

gauravsingh1095
2020-06-30 08:04
``` import au.com.dius.pact.core.model.Interaction; import au.com.dius.pact.core.model.Pact; import au.com.dius.pact.provider.junit.IgnoreNoPactsToVerify; import au.com.dius.pact.provider.junit.Provider; import au.com.dius.pact.provider.junit.State; import au.com.dius.pact.provider.junit.loader.PactBroker; import au.com.dius.pact.provider.junit5.HttpTestTarget; import au.com.dius.pact.provider.junit5.PactVerificationContext; import au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider; import com.github.tomakehurst.wiremock.WireMockServer; import org.apache.http.HttpRequest; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestTemplate; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit.jupiter.SpringExtension; import static com.github.tomakehurst.wiremock.client.WireMock.*; /** * Created by gaurav13.singh on Jun, 2020 **/ @ExtendWith(SpringExtension.class) @Provider("Provider") @PactBroker(host = "host", port = "30953") @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, properties = {"server.port=5009", "redis-service.ribbon.listOfServers: localhost:5011"}) @IgnoreNoPactsToVerify public class PactTestWire { private static final int WIREMOCK_PORT = 5011; private WireMockServer wireMockServer; @BeforeEach public void setup() { wireMockServer = new WireMockServer(WIREMOCK_PORT); wireMockServer.stubFor(get( urlEqualTo("http://redis-service")) .willReturn(aResponse() .withStatus(200) .withHeader("Content-Type", "application/json") .withBody("[\"Tables\",\"Chairs\"]") )); wireMockServer.start(); } @BeforeEach void setTarget(PactVerificationContext context) { HttpTestTarget target = new HttpTestTarget("localhost", 5009); context.setTarget(target); } @State("with session") public void withSession() { System.out.println("with session"); } @State("without session") public void withoutSession() { System.out.println("without session"); } @AfterEach public void tearDown() { wireMockServer.stop(); } @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void testTemplate(Pact pact, Interaction interaction, HttpRequest request, PactVerificationContext context) { request.addHeader("cookie", "cookies"); context.verifyInteraction(); } }```

gauravsingh1095
2020-06-30 08:06
Tried this too ``` import au.com.dius.pact.provider.junit.IgnoreNoPactsToVerify; import au.com.dius.pact.provider.junit.Provider; import au.com.dius.pact.provider.junit.State; import au.com.dius.pact.provider.junit.loader.PactBroker; import com.jio.jpw.exception.JPWException; import com.jio.jpw.model.LogModel; import com.jio.jpw.utils.JsonUtils; import com.jio.jpw.utils.LogHelper; import com.jio.referencedatainquiry.controller.ReferenceDataInquiryController; import com.jio.referencedatainquiry.domain.DealerAddress; import com.jio.referencedatainquiry.proxy.RedisProxy; import com.jio.referencedatainquiry.services.LookupRelatedValueService; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.mockito.InjectMocks; import org.mockito.Mock; import org.springframework.boot.SpringApplication; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.web.context.ConfigurableWebApplicationContext; import javax.servlet.http.Cookie; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; /** * Created by gaurav13.singh on Jun, 2020 **/ @RunWith(PactRunner.class) @Provider("provider") @PactBroker(host = "host", port = "30953") @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, properties = {"server.port=5009"}) @IgnoreNoPactsToVerify public class PactTest { private static ConfigurableWebApplicationContext application; @TestTarget public final Target target = new HttpTarget(5009); @Mock private RedisProxy mockRedisProxy; @Mock private MockHttpServletRequest servletRequest; @MockBean private LogModel logModel; @Mock private LookupRelatedValueService mockLookupRelatedValueService; @InjectMocks private ReferenceDataInquiryController referenceDataInquiryControllerUnderTest; @BeforeClass public static void start() { application = (ConfigurableWebApplicationContext) SpringApplication.run(ReferenceDataInquiryApplication.class); } @Before public void setUp() { initMocks(this); servletRequest = new MockHttpServletRequest(); servletRequest.setCookies(new Cookie("JPSSSessionID", "val"), new Cookie("authToken", "value")); when(mockRedisProxy.getData(any())).thenReturn(TestData.SESSION_DATA); servletRequest.addHeader("a", "1216"); logModel = LogHelper.createBasicLogModel(servletRequest); logModel.setSessionData(TestData.SESSION_DATA); } @State("with session") public void withSession() throws JPWException { final DealerAddress expectedResult = JsonUtils.getBeanByJson(TestData.DealerAddress, DealerAddress.class); when(mockLookupRelatedValueService.lookupRelatedValue(any(), any())).thenReturn(expectedResult); final DealerAddress result = referenceDataInquiryControllerUnderTest.lookupRelatedValue("673020", servletRequest); assertEquals(expectedResult, result); System.out.println("with session"); } @State("without session") public void withoutSession() { System.out.println("without session"); } @After public void after() { } }```

gauravsingh1095
2020-06-30 08:23
am I doing something wrong?

chandanakurumeti27
2020-06-30 10:52
@phil.endsley is it possible while using pact js as well?

chandanakurumeti27
2020-06-30 10:52
some example link please?

chandanakurumeti27
2020-06-30 11:51
Hi, How can i return value from provider states to the request body in the contract before running provider tests when th consumer service is javascript based one. I couldnt find ?valuefromproviderstate? feature in pact JS, so how can i actually accomplish this ? FYI, my consumer is javascript based service and provider is java based service

chandanakurumeti27
2020-06-30 11:51
Kindly someone please help me on this?


phil.endsley
2020-06-30 12:35
Try using `org.springframework.boot.test.mock.mockito.MockBean` instead. `@Mock` creates a plain old mock you can use. This is useful for unit tests where you're creating the objects yourself with constructors. `@SpringBootTest` is spinning up the Spring application context, so all the objects are being created through DI. `@MockBean` will create a Mockito mock and inject it into the Spring context for you.

phil.endsley
2020-06-30 12:47
What is the specific issue you're running into? Your JS Consumer will run tests against the contract it defines. The Consumer tests themselves don't do anything with the Provider. When you're writing the pact on the JS side, you're in charge of defining the state and response body. You're in control of all the data. If your Consumer tests need something from the state, won't you already know ahead of time what value you're expecting? On the Provider side, you can use the `valueFromProviderState` methods to get values for the response you're returning.

gauravsingh1095
2020-06-30 14:32
Thanks @phil.endsley, I?ll try this

mbieganski.infomatt
2020-06-30 20:18
Hi. I'm having problem with ZonedDateTime. On Consumer side everything looks and works fine with ```body.datetime("creationDate", "yyyy-MM-dd'T'HH:mm[:ss.SSS]XXX'['VV']'", Instant.ofEpochMilli(1592317859528L));``` When running provider tests I'm getting below. I'm using version 4.1.4 ``` Unable to parse "2020-05-08T15:25:30+09:00[Japan]" with yyyy-MM-dd'T'HH:mm[:ss.SSS]XXX'['VV']' using java.time.format.DateTimeFormatter. Attempting to parse using org.apache.commons.lang3.time.DateUtils to guarantee backwards compatibility with versions < 4.1.1. Please update your patterns in your pact tests as this may not be supported in future versions. Request Failed - Format 'V' not supported``` Any ideas?

antonello
2020-06-30 20:33
Did this work with previous versions of pact-jvm? Or is it a new test?

mbieganski.infomatt
2020-06-30 20:39
I have initially created issue #1107 and have been using work around. Recently have switched to 4.1.4 and decided to update tests and discovered this issue. Also looks like `or` and `and` PM matchers are missing `datetime` handling.

antonello
2020-06-30 20:42
This one for @uglyog I reckon. We had problems when switching to 4.1.x and had to implement the fall back that you see mentioned in the warning

antonello
2020-06-30 20:43
To me if looks like your date cannot be parsed with that format by neither DateTimeFormatter nor DateUtils

antonello
2020-06-30 20:46
I am by no means an expert of date formats, but are you sure that format can ever work with that date?

antonello
2020-06-30 20:47
Didn?t mean to send the message above to the channel :man-facepalming::skin-tone-2:

mbieganski.infomatt
2020-06-30 20:48
yeah it works just fine on consumer side and was suggested by @uglyog https://github.com/DiUS/pact-jvm/issues/1107#issuecomment-640160063

antonello
2020-06-30 20:50
The consumer side doesn?t attempt to parse as far as I?m aware - it will just put the format and the example in the pact

antonello
2020-06-30 20:50
The format suggested by @uglyog is different from the one you?re using though

mbieganski.infomatt
2020-06-30 21:06
the error clearly points to `Format 'V' not supported` unless the message is misleading. Consumer is parsing the the example `Instant.ofEpochMilli(1592317859528L)` and puts `"2020-06-16T16:30:59.528+02:00[Europe/Warsaw]"` to pact so format should be working just fine

uglyog
2020-06-30 23:18
@mbieganski.infomatt You need to quote the square brackets in `[:ss.SSS]`

mbieganski.infomatt
2020-07-01 06:03
@uglyog it doesn't work. `JSON conversion problem: Text '2020-06-16T16:30[:ss.SSS]+02:00[Europe/Warsaw]' could not be parsed at index 16;`

uglyog
2020-07-01 06:04
Sorry, I meant the brackets only

uglyog
2020-07-01 06:04
`'[':ss.SSS']'`

mbieganski.infomatt
2020-07-01 06:07
`JSON conversion problem: Text '2020-06-16T16:30[:59.528]+02:00[Europe/Warsaw]' could not be parsed at index 16;` I don't think so that when using optional section I need quote https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html ?

uglyog
2020-07-01 06:12
Ah, yes, you're correct

uglyog
2020-07-01 06:15
I think the error is misleading, we've lost the original error when it tries the fallback

uglyog
2020-07-01 06:18
The problem may be that Japan is not a valid timezone ID, it should be `Asia/Tokyo`

mbieganski.infomatt
2020-07-01 06:20
hmm I think I tried with `Europe/Warsaw` but might try again. Have you added `datetime` handling for `and/or` matching rules?

uglyog
2020-07-01 06:23
The datetime handling was changed that if DateTimeFormatter fails to parse, it falls back to trying the older parser which is based on SimpleDateFormat. But the issue is the first error is lost, and it is showing the error from SimpleDateFormat which does not support time zone IDs

mbieganski.infomatt
2020-07-01 06:26
I tried with valid timezone but same error. Would you like me to raise an issue? ```Unable to parse "2020-05-08T15:25:30+09:00[Asia\/Tokyo]" with yyyy-MM-dd'T'HH:mm[:ss.SSS]XXX'['VV']' using java.time.format.DateTimeFormatter.```

uglyog
2020-07-01 06:31
Why is there a backslash in the zone id?

uglyog
2020-07-01 06:31
I tested Japan, and it works as a zone ID

uglyog
2020-07-01 06:32
```groovy:000> DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm[:ss.SSS]XXX'['VV']'").parse('2020-07-01T16:29:35.574+10:00[Australia/Melbourne]') ===> {OffsetSeconds=36000, InstantSeconds=1593584975},ISO,Australia/Melbourne resolved to 2020-07-01T16:29:35.574 groovy:000> DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm[:ss.SSS]XXX'['VV']'").parse('2020-07-01T16:29:35.574+09:00[Asia/Tokyo]') ===> {OffsetSeconds=32400, InstantSeconds=1593588575},ISO,Asia/Tokyo resolved to 2020-07-01T16:29:35.574 groovy:000> DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm[:ss.SSS]XXX'['VV']'").parse('2020-07-01T16:29:35.574+09:00[Japan]') ===> {OffsetSeconds=32400, InstantSeconds=1593588575},ISO,Japan resolved to 2020-07-01T16:29:35.574```

uglyog
2020-07-01 06:33
But your datetime fails

uglyog
2020-07-01 06:33
```groovy:000> DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm[:ss.SSS]XXX'['VV']'").parse('2020-05-08T15:25:30+09:00[Asia/Tokyo]') ERROR java.time.format.DateTimeParseException: Text '2020-05-08T15:25:30+09:00[Asia/Tokyo]' could not be parsed at index 16```

uglyog
2020-07-01 06:34
Because you don't have any milliseconds, I'm guessing

uglyog
2020-07-01 06:34
```groovy:000> DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm[:ss][.SSS]XXX'['VV']'").parse('2020-05-08T15:25:30+09:00[Asia/Tokyo]') ===> {OffsetSeconds=32400, InstantSeconds=1588919130},ISO,Asia/Tokyo resolved to 2020-05-08T15:25:30```

uglyog
2020-07-01 06:35
:point_up: You need to have the seconds and milliseconds as different optionals

mbieganski.infomatt
2020-07-01 06:41
awesome great :slightly_smiling_face: thanks! should it also work with AND/OR matching rules e.g PM.timestamp ?

uglyog
2020-07-01 06:41
Yes, it should (in theory)

antonello
2020-07-01 07:10
How about this to show the first exception? https://github.com/DiUS/pact-jvm/pull/1152

mbieganski.infomatt
2020-07-01 08:30
@uglyog not sure if expected but when I have contract defined as below for request body ```body.or("creationDate", INSTANT_TIME, PM.nullValue(), PM.timestamp("yyyy-MM-dd'T'HH:mm[:ss][.SSS]XXX'['VV']'"));``` when I send POST with creationDate being null I'm getting ```Unable to parse null with yyyy-MM-dd'T'HH:mm[:ss][.SSS]XXX'['VV']' using java.time.format.DateTimeFormatter.``` I would expect that using multiple matchers I can send null?

chandanakurumeti27
2020-07-01 09:36
When both consumer and provider services are java based, it is in the consumer service where we define the expectations before running the consumer tests,right. And Its needed to mention this`"valuefromproviderstate"` keyword in the expected request body. only then before running provider tests if i return something from my provider `statechange()` method, The value returned will replace the value exists request body in the contract.Atleast thats how i understand the flow is. Right now, My issue is as i said my consumer service is javascript based one and am using pactJS to write consumer tests and I could really use ?valuefromproviderstate? feature there as it doesnt exist in pact js framework(got this info from pact JS channel).So how could i make sure that, the value in the request body will be replaced by the value which i return from my provider statechange() method. Pointing it again,My provider service is java based one here.

chandanakurumeti27
2020-07-01 09:40
Here the value i want to replace is `sessionuid` with the one which is returned from the provider state and i actually generate this sessionuid inside the providerstate change method by sending the request to `start the session` api and i want that sessionuid(which i got when i start the session inside statechange method and not the one i have in contract) to use in the request body while running the provider states

rafael.espillaque
2020-07-01 11:37
Can I split Message Contracts Verification methods into different Test Classes? Currently I have 2 Consumers with 1 Interaction each and 1 Provider that needs to verify those 2 Contracts. In the Provider codebase I have 2 different Test Classes. I?m seeing that the first test class finds the 2 Contracts and it?s somehow instantiating the second class and calling the PactVerifyProvider method but since it wasn?t run by JUnit, some fields in that class are null.

antonello
2020-07-01 11:42
Hey @rafael.espillaque. Yes, you can split your state change methods into different classes/interfaces. https://github.com/DiUS/pact-jvm/tree/master/provider/junit#using-multiple-classes-for-the-state-change-methods

rafael.espillaque
2020-07-01 12:57
Thanks @antonello but not sure how to do that with Messages. I don?t have @State annotations, just @PactVerifyProvider

antonello
2020-07-01 12:58
Ah sorry - I misread your message

rafael.espillaque
2020-07-01 12:58
no problem, was useful

rafael.espillaque
2020-07-01 12:59
this could be the key: ```/** * Test target for use with asynchronous providers (like with message queues). * * This target will look for methods with a @PactVerifyProvider annotation where the value is the description of the * interaction. * * @property packagesToScan List of packages to scan for methods with @PactVerifyProvider annotations. Defaults to the * full test classpath. */ open class AmpqTestTarget(val packagesToScan: List<String> = emptyList()) : TestTarget {```

rafael.espillaque
2020-07-01 13:12
:confused: it?s not enough ```context.setTarget(new AmpqTestTarget(Collections.singletonList(getClass().getPackageName())));``` after adding that, now it only finds one of the @PactVerifyProvider method but it?s still trying to verify the contract

rafael.espillaque
2020-07-01 13:39
I understand the design could be that different classes have different @PactVerifyProvider so only 1 Pact test is needed but I?m finding that those classes don?t have its @Before called, nor its Spring Context initialised.

jgfarias42
2020-07-02 07:23
[can-i-deploy] Hi all, I?m having problems figuring out what is the equivalent in the JVM / Maven tools to https://docs.pact.io/pact_broker/can_i_deploy_https://docs.pact.io/pact_broker/can_i_deploy_ step, to be performed after the _mvn pact:can-i-deploy_ is successful. I?ve found this issue talking about setting _pact.provider.tag_ on the POM, but my understanding is that it would be static, rather than defined on the fly by the deployment script, just like I do with _mvn pact:can-i-deploy_. https://github.com/DiUS/pact-jvm/issues/823 I?ve also tried _mvn pact:publish -Dpact.publish.tag=_MyEnv, but this particular service I have doesn?t consume data, so no Pacts exist and this command fails. Would I need to have the Pact Broker itself available to perform this?

wesleythomaswilliams
2020-07-02 08:14
We do this in a pipeline stage: ```' mvn -B -f pom.xml pact:publish' + ' -Dpact.consumer.version=' + env.GIT_COMMIT + ' -Dpact.tag=' + env.GIT_BRANCH```

giuseppe.salvatore
2020-07-02 08:38
has joined #pact-jvm

giuseppe.salvatore
2020-07-02 08:39
Sweet, this was exactly what I was looking for :+1: I was asking this question in the #general channel just yesterday

jgfarias42
2020-07-02 09:42
@wesleythomaswilliams I still got the same error: ?myservice/target/pacts does not exist, skipping uploading of pacts?, because I am working on a provider that has no downstream dependencies - therefore it doesn?t define any consumer contract, only verifies itself against upstream dependencies Does this command of yours add this tag to the *provider* of a particular verification in the Matrix? Screenshot 2020-07-02 at 11.36.37

wesleythomaswilliams
2020-07-02 10:02
Our provider tagging happens when the provider tests are run: ```' mvn -B -f pom.xm test -Pcontract-tests' + ' -Dpact.provider.version=' + env.GIT_COMMIT + ' -Dpact.verifier.publishResults=true' + ' -Dpact.provider.tag=' + env.GIT_BRANCH```

wesleythomaswilliams
2020-07-02 10:06
We have a generic pipeline that runs for both our consumers and providers, so there's some conditional elements based on if a service is a consumer or provider. e.g. a provider service doesn't do the pact:publish, a consumer doesn't do the provider piece above.

jgfarias42
2020-07-02 11:16
I didn?t get how / when you push a tag for the environment that the service was deployed. The building phase flow I was able to do: 1 - Create the consumer contracts; 2 - Verify the contracts on the provider; Now I am moving to the deployment phase. What I was able to do was to run can-i-deploy: ```mvn pact:can-i-deploy -Dpacticipant='MyService' -DpacticipantVersion=${myService.version}-SNAPSHOT -DtoTag=${envName}``` This will look for failed verifications for the other services in the environment ?envName?. However, for this to work, as mentioned in the documentation above, I need to simply add an additional tag for the environment, not both run the verification *and* upload a tag.

jgfarias42
2020-07-02 11:18
The Ruby / Pact Broker Client steps are as follows: https://docs.pact.io/pact_broker/can_i_deploy#summary I did the first one, but I?m stuck in doing the second.

kristine.jetzke
2020-07-02 13:12
You need to run this step manually. So to answer the original question: > Would I need to have the Pact Broker itself available to perform this? Yes

kristine.jetzke
2020-07-02 13:15
manually = using the pact broker CLI


kristine.jetzke
2020-07-02 13:19
since it?s not usually done during a build but after a deployment maven might also not be the best tool (unless you do your deployment with maven)

jgfarias42
2020-07-02 13:20
I am able to save my pom as artefact and then run maven plugins there. It adds a bit of time to the builds, but I think it?s worth given that I can block builds at the beginning with can-i-deploy.

kristine.jetzke
2020-07-02 13:22
I did not get that. Can?t you block build independent of the tool you use? But I guess this kind of a different topic. From what I can see in the code I would say that the maven plugin currently does not support this separate tagging step. But since there is a `can-i-deploy` step maybe you can create a PR and add it. What do you think @uglyog

jgfarias42
2020-07-02 15:35
Thanks for the diagnosis @kristine.jetzke I will take a look at how to create this Mojo, sounds fun :smile:

antonello
2020-07-02 15:58
@phil.endsley Have you been using `4.1.5`? Because we?ve just tried it and it doesn?t work for us. It can?t find any pacts.

phil.endsley
2020-07-02 16:20
I have not yet. It was on my list, but other items came up this week. I can give it a shot right now though

phil.endsley
2020-07-02 16:20
@antonello Did you switch to version selectors, or are you still using tags?

antonello
2020-07-02 16:21
still using tags

antonello
2020-07-02 16:42
from a second test, it seems to be working for me

antonello
2020-07-02 16:42
but I need to check with my colleague who I was pairing with as it wasn?t working on his machine

phil.endsley
2020-07-02 16:47
It fails for me as well

phil.endsley
2020-07-02 16:47
I see the issue

phil.endsley
2020-07-02 16:49
I added a default value for `consumerVersionSelectors` to support system properties. We fall back to using `tags` if `consumerVersionSelectors` is empty, but it never is now

phil.endsley
2020-07-02 16:52
As a workaround, you can set `consumerVersionSelectors = {}` . There's still another issue to figure out though, since it should be falling back to getting the latest version if nothing is specified

rafael.espillaque
2020-07-02 16:52
Any ideas please?

phil.endsley
2020-07-02 16:53
I think I'll have time later tonight to take a look and work on a fix

antonello
2020-07-02 17:01
we?re definitely missing some tests on `pact-jvm`

antonello
2020-07-02 17:02
we shouldn?t be able to release something that doesn?t work to this extent

antonello
2020-07-02 17:02
the tests should tell you

antonello
2020-07-02 17:03
workaround doesn?t really work for us as we have far too many providers

antonello
2020-07-02 17:03
my suggestion would be to revert your changes

antonello
2020-07-02 17:04
until they?re fixed and definitely working

antonello
2020-07-02 17:04
otherwise we can?t release

antonello
2020-07-02 17:04
your changes are incredibly important though

antonello
2020-07-02 17:07
and 4.1.5 should be deprecated

phil.endsley
2020-07-02 17:10
So do I just open a pr against master with the change reverted?

antonello
2020-07-02 17:12
@uglyog is sleeping, but I?d say yes, unless you can fix it by the end of the day

antonello
2020-07-02 17:15
I think we should re-release a version that works ASAP because otherwise 4.1.5 is pretty borked for anyone who installs it.

antonello
2020-07-02 17:19
what?s your github handle?

phil.endsley
2020-07-02 17:19
pendsley

emanuele.ivaldi
2020-07-02 17:21
marked as a WIP as we haven't had the chance to test it locally - will remove the WIP from the title when it's tested :thumbsup:

antonello
2020-07-02 17:22
@phil.endsley

phil.endsley
2020-07-02 19:13
Appreciate you bringing this up. Apologies for any inconveniences it's causing :disappointed:

antonello
2020-07-02 19:13
No worries!

antonello
2020-07-02 19:15
If nothing imho this is highlighting that it?d be great to look into whether more/different tests might help us spot issues before releasing. Perhaps something external to the repo as @bethskurrie suggested.

antonello
2020-07-02 19:32
Saw your PR @phil.endsley :muscle: . Some tests are failing.

phil.endsley
2020-07-02 19:32
Just pushed a fix for the tests

antonello
2020-07-02 20:50
verified locally and it works!

kristine.jetzke
2020-07-02 21:12
Do you have a minimal example you can provide?

phil.endsley
2020-07-02 21:16
I haven't personally done this. But it's mentioned in the junit docs as being possible. https://docs.pact.io/implementation_guides/jvm/provider/junit/#returning-values-that-can-be-injected https://github.com/pact-foundation/pact-specification/tree/version-3#introduce-example-generators > You can have values from the provider state callbacks be injected into most places (paths, query parameters, headers, *bodies*, etc.). This works by using the V3 spec generators with provider state callbacks that return values. It _sounds like_ (the way I'm interpreting it) you can use a generator on the js side to create the Pact, then use the state callback on the Java side to fill it in with the value you really want. I haven't had to do this before though. Maybe @uglyog or @matt.fellows can answer this better?

antonello
2020-07-02 22:46
@uglyog if we could get these two reviewed/approved, I can release 4.1.6 first thing tomorrow morning. https://github.com/DiUS/pact-jvm/pull/1156 https://github.com/DiUS/pact-jvm/pull/1158

uglyog
2020-07-02 23:22
@chandanakurumeti27 Javascript doesn't support any of the V3 features, so it will not generate a Pact file with the correctly configured generators for this to work

uglyog
2020-07-02 23:25
I don't think we can re-release 4.1.5, the only thing we can do is release 4.1.6 and update the release notes on Github to state it has an issue.

bethskurrie
2020-07-03 03:19
It's the moment I know you've all been waiting for - the docs now have a comparison between Pact and Spring Cloud Contract. :party_parrot: Kristine has made it happen https://docs.pact.io/getting_started/comparisons#how-does-pact-differ-from-spring-cloud-contract

antonello
2020-07-03 10:51
I?ve released 4.1.6 this morning and added a note to 4.1.5 https://github.com/DiUS/pact-jvm/releases/tag/4_1_5

dattasai.chunduru
2020-07-03 13:40
Hi I have to pass 2 query parameters in my URL and I am passing them like this

dattasai.chunduru
2020-07-03 13:40
is this the right way of adding the query parameters


dattasai.chunduru
2020-07-03 15:03
Hi When I am trying to run the provider side verification I am getting error as Execution default-cli of goal au.com.dius:pact-jvm-provider-maven_2.12:3.5.10:verify failed: No signature of method: static http://au.com.dius.pact.model.PactReader.queryStringToMap() is applicable for argument types: (java.util.LinkedHashMap) values: [[city_id:[4487042], key:[1c7fdbc64572463f9ebe140ff3909050]]] [ERROR] Possible solutions: queryStringToMap(java.lang.String), queryStringToMap(java.lang.String, boolean)


dattasai.chunduru
2020-07-03 15:05
and my provider side code is

dattasai.chunduru
2020-07-03 15:05
can anyone please help me on this

kristine.jetzke
2020-07-03 20:35
It looks like the query has the wrong format. It is a map but needs to be a string. Can you paste the code that generates the contract?


kristine.jetzke
2020-07-03 20:39
instead of ```.query("city_id=4487042) .query("key=1c7fdbc64572463f9ebe140ff3909050")``` try ```.query("city_id=448704&key=1c7fdbc64572463f9ebe140ff3909050")```

uglyog
2020-07-04 03:17
No, the second will overwrite the first. Just append a `&` between them with one call

uglyog
2020-07-04 03:18
This looks like a defect. Can you raise a Github issue for it?

uglyog
2020-07-06 07:11
@phil.endsley @antonello I'm going to be working on an implementation of handling different types of objects in lists (i.e. polymorphic collections). I might leave the 4.1.x branch to now stabilise, and move development when I start that work on 4.2.x. It does mean that master may track 4.2.x at some point, and we would need to backport fixes to 4.1.x

antonello
2020-07-06 07:13
So any new releases for the time being from 4.1.x?

uglyog
2020-07-06 07:14
We can do releases from both branches when needed

antonello
2020-07-06 07:14
:ok_hand::skin-tone-2:

antonello
2020-07-06 07:14
I didn?t update 4.1.x after my release last week by the way

uglyog
2020-07-06 07:15
Should be ok, will only be a fast forward because there shouldn't be other commits on that branch

francesco.bartoli
2020-07-06 08:05
has joined #pact-jvm

hadjaliabir
2020-07-06 15:15
Hello ! how can i resolve "failed to invoke pact method " . i use java/junit/eclipse, i added the jars using build path

uglyog
2020-07-06 23:11
A little bit more information will help. How are you running things, what are you running and what jars did you add using the build path?

dattasai.chunduru
2020-07-07 06:58
@kristine.jetzke I have taken this site as reference https://docs.pact.io/getting_started/matching/

dattasai.chunduru
2020-07-07 07:01
@kristine.jetzke This is my consumer side code

ashish_garg5
2020-07-07 09:57
Hi All, @PactBroker(host = "${pact.broker.host}", port = "${pact.broker.port}") I have added this annotation in my test class and i was passing these values while doing maven clean install. How i can configure these host and port in my pom.xml ? Thanks.

matt.fellows
2020-07-07 10:10
Aren't they references to environment variables?

matt.fellows
2020-07-07 10:10
Presumably however you normally would expose env vars

ashish_garg5
2020-07-07 10:18
they references to ENV variables but if someone only wants to do mvn clean install locally then in that case it will fail

matt.fellows
2020-07-07 10:28
If they aren't sensitive or dynamic then you could just hard code them

fernando.martin
2020-07-07 14:39
has joined #pact-jvm

uglyog
2020-07-07 23:39
They are JVM system properties, not env vars

matt.fellows
2020-07-07 23:54
cool. Same difference

dattasai.chunduru
2020-07-08 08:17
Hi All

dattasai.chunduru
2020-07-08 08:18
I am trying to do the validation for response body by using PactDslJsonBody my response looks like this [ { "id": 54365477, "name": "Wils", "phone": "" } ] and my validation code looks like .body(new PactDslJsonBody() .array() .object() .numberValue("id", 54365477) .closeObject() .closeArray()).toPact()

dattasai.chunduru
2020-07-08 08:19
It is showing error for me stating can not initiate PACT method. Can anyone tell me how can we write an array without any name

abubics
2020-07-08 08:22
From memory, it's not supported . . . I'm not sure of the official reason. The reason I would recommend against such an API is it's inextensible from the root, and not self-describing.

antonello
2020-07-08 08:37
With your array being on the root, if you?re happy to use matchers, which would be my advice anyway, you should be able to do this: https://github.com/DiUS/pact-jvm/tree/master/consumer#root-level-arrays-that-match-all-items

dattasai.chunduru
2020-07-08 08:44
Actually I got the output

dattasai.chunduru
2020-07-08 08:44
Thankyou @antonello for your quick reply in both the places

antonello
2020-07-08 08:45
You?re welcome :slightly_smiling_face:

ashish_garg5
2020-07-08 10:57
Hi All, I have added basic auth in my pact broker using the below commands. PACT_BROKER_BASIC_AUTH_USERNAME: PACT_BROKER_BASIC_AUTH_PASSWORD: Now how can i pass these in my mvn clean install command ?

francislainy.campos
2020-07-08 11:02
Sorry if my question doesn't make much sense, but I have a situation where I've access to a contract as a .json file but it's not published yet and it may take some time for this to happen. I want to start writing the verification tests for it, so was thinking of pasting this file manually under the pact/folder and connect to it rather than an online broker? I think I've seen something like this done somewhere before. Is this really possible? If so, could I get a sample please? Thanks very much.

hadjaliabir
2020-07-08 11:05
I had a problem with maven because of my company restrictions, so i had to add jars manually to the project , it turns out that i have a missing jar and duplicated versions ... Now i am able to run a maven projet (added cacerts), and everything is fine ... thank you :blush:

francislainy.campos
2020-07-08 11:10
I've tried something like this (with and without / at the start) but I'm be missing something else since it won't work.

ashish_garg5
2020-07-08 11:26
i think you have to give target folder as well. target/pacts

wesleythomaswilliams
2020-07-08 11:26
Our provider tests contain this: ```@PactBroker( host = "${pact.broker.host}", scheme = "https", port = "443", authentication = @PactBrokerAuth(token = "${pact.broker.token}"))``` So we use a token rather than username/password. And we store that token in our POM (in our surefire plugin for the provider and the pact plugin for our consumer) and our jenkinsfile to pass to can-i-deploy during our pipeline. It's a bit messy at the moment as I'd like to store it in one location.

wesleythomaswilliams
2020-07-08 11:27
```<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <systemPropertyVariables> <pact.broker.host>url</pact.broker.host> <pact.broker.token>xyz</pact.broker.token> <pact.verifier.publishResults>false</pact.verifier.publishResults> <pact.provider.version>${pact.provider.version}</pact.provider.version> <pact.provider.version.trimSnapshot>false</pact.provider.version.trimSnapshot> </systemPropertyVariables> </configuration> </plugin>```

francislainy.campos
2020-07-08 11:27
Yes, just tried that too. Both target/pacts and /target/pacts but same error I'm afraid. Tried also the absolute path for the .json file but same issue.

wesleythomaswilliams
2020-07-08 11:28
```<plugin> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>${pact.version}</version> <configuration> <projectVersion>${pact.consumer.version}</projectVersion> <pactDirectory>${project.build.directory}/pacts</pactDirectory> <pactBrokerUrl>url</pactBrokerUrl> <pactBrokerToken>xyz</pactBrokerToken> <pactBrokerAuthenticationScheme>Bearer</pactBrokerAuthenticationScheme> <skipPactPublish>false</skipPactPublish> <tags> <!--suppress UnresolvedMavenProperty --> <tag>${pact.tag}</tag> </tags> </configuration> </plugin>```

antonello
2020-07-08 11:28
Have you tried just `pact`

antonello
2020-07-08 11:28
without the slash

francislainy.campos
2020-07-08 11:29
Yeah

ashish_garg5
2020-07-08 11:30
so in consumer we don't have @PactBroker annotation so only we have to add in pom.xml ?

wesleythomaswilliams
2020-07-08 11:32
For our consumer, we have it in the POM in the Pact plugin as above, which I believe is where it's used by the `mvn pact:publish` command.

antonello
2020-07-08 11:32
which package is `PactSource` coming from?

ashish_garg5
2020-07-08 11:33
ok thanks, so instead of token if i have to add username and password then there is anyway or any useful link if you are aware ?

francislainy.campos
2020-07-08 11:33
I believe is the pacts folder with the .json file?

antonello
2020-07-08 11:33
It has to be `http://au.com.dius.pact.provider.junitsupport.loader.PactFolder` as mentioned here: https://pact-foundation.slack.com/archives/C9UN99H24/p1592924865155700

antonello
2020-07-08 11:34
where are you importing the `PactFolder` annotation from?

francislainy.campos
2020-07-08 11:36
```import au.com.dius.pact.core.model.annotations.PactFolder;```

antonello
2020-07-08 11:36
Se my message above then

francislainy.campos
2020-07-08 11:37
I'm trying to add this here but getting an error

antonello
2020-07-08 11:37
it?s the wrong one

antonello
2020-07-08 11:37
You need to use `http://au.com.dius.pact.provider.junitsupport.loader.PactFolder`

francislainy.campos
2020-07-08 11:37
Yes, this one that I mean.

antonello
2020-07-08 11:37
which version of pact-jvm are you using?

francislainy.campos
2020-07-08 11:38
4..0.5

wesleythomaswilliams
2020-07-08 11:38
Looking now, but I think it's, `pactBrokerUsername` and `pactBrokerPassword`

francislainy.campos
2020-07-08 11:38
Sorry, 4.0.1

antonello
2020-07-08 11:38
ok, so then the package structure would be different

ashish_garg5
2020-07-08 11:38
yeah i got it thanks :slightly_smiling_face:

francislainy.campos
2020-07-08 11:40
I just tried it this way too ../pacts

antonello
2020-07-08 11:40
it should be in `http://au.com.dius.pact.provider.junit.loader.PactSource`

francislainy.campos
2020-07-08 11:42
Thanks so much! It worked now. :slightly_smiling_face:

antonello
2020-07-08 11:43
:ok_hand:

francislainy.campos
2020-07-08 11:43
Have a great day and appreciate your help.

antonello
2020-07-08 11:48
You?re welcome! Enjoy your day!


dattasai.chunduru
2020-07-08 18:13
Hi Can anyone please provide the yaml file for PACTBROKER with authentication

kristine.jetzke
2020-07-08 19:44
hm I cannot reproduce it even when I downgrade to version _3.5.10_

kristine.jetzke
2020-07-08 19:45
how does the generated contract look like?

kristine.jetzke
2020-07-08 19:46
Is it an option for you to upgrade to a newer version and see if it works? If not, could you post a minimal example that reproduces the problem? Preferable as a GitHub issue.

kristine.jetzke
2020-07-08 19:50
@antonello Do you know why there are those two annotations btw? Someone else recently contacted my about the same issue - they pacts were not loaded and in the end it turned out they used the import from the wrong package.

antonello
2020-07-08 19:54
I don?t know off the top of my head - I?d have to have a look at the implementation

kristine.jetzke
2020-07-08 20:34
I just realized it?s even in one of the the workshops wrong? https://github.com/pactflow/example-provider-java-kafka/pull/1 :slightly_smiling_face:

kristine.jetzke
2020-07-08 20:36
:thinking_face: should I create a ticket for pact-jvm to look into it? Especially if you?re just starting out with pact it might lead to unnecessary frustration

phil.endsley
2020-07-08 20:56
@uglyog mentioned wanting to change when it was brought up a week or so ago

kristine.jetzke
2020-07-08 21:10
How about adding the https://github.com/DiUS/pact-jvm/tree/master/provider/junit#filtering-by-consumer annotation to the respective classes? I don?t know though if that affects the possibility to publish results or has any other side effects. From a quick check I did I would say no side effects. The main drawback I would say is that you have to remember to add new consumers.

kristine.jetzke
2020-07-08 21:12
In general I also find the use of `@PactVerifyProvider` across multiple classes confusing. It can only work if the annotated methods don?t need any fields from the class. And it?s also confusing to me that if there are two classes with `AmpqTestTarget` targets and `@PactVerifyProvider` each that each class calls the other classes methods.

kristine.jetzke
2020-07-08 21:17
Maybe it?s worth it to create a bug?

uglyog
2020-07-09 00:04
The one is for defining the pact source for verifying a provider, the other to overwrite the directory where the pacts get written to in a consumer test. It's unfortunate they ended up with the same name.

matt.fellows
2020-07-09 00:06
Can you elaborate on why the publishing is going to take so long?

matt.fellows
2020-07-09 00:06
Are you waiting for a broker to be setup or something?

francislainy.campos
2020-07-09 08:00
It's done by another team and they will submit it after they are finished with the contract for some other apis that are still being done.

matt.fellows
2020-07-09 08:14
do they not publish the contract on every build and just tag it as a feature?

rafael.espillaque
2020-07-09 11:00
will try the annotation and create the bug, thanks @kristine.jetzke !

uglyog
2020-07-11 23:57
/github subscribe list features

praneethkumar
2020-07-12 17:45
Hi , Does anyone have a good example of a POST test for consumer I can refer to please ?

uglyog
2020-07-13 23:18
@uglyog has renamed the channel from "pact-jvm-help" to "pact-jvm"

aliaksandr.valadzko
2020-07-14 09:49
has joined #pact-jvm

aliaksandr.valadzko
2020-07-14 09:49
Hello:slightly_smiling_face: I try to set up Pact Provider tests in java using `@RunWith(PactRunner.class)` To initialize Spring beans I have to use `BeforeClass` section: ``` @BeforeClass public static void contextSetUp() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.register(PactContext.class); context.refresh(); SomeServiceMockStubs = context.getBean(SomeServiceMockStubs.class); ... }``` Is there a chance to simplify it, and use `Autowired` annotation like it is done in `@RunWith(SpringJUnit4ClassRunner.class)` ? ``` @Autowired protected SomeServiceMockStubs someServiceMockStubs;``` Thanks in advance!

jason
2020-07-14 10:17
has joined #pact-jvm

kristine.jetzke
2020-07-14 12:14
Are you using junit 4 or 5?


kristine.jetzke
2020-07-14 12:21
I don?t think there is a `HttpTarget` yet for Junit 5. Instead you can do this: ```@LocalServerPort private int port; @BeforeEach void before(PactVerificationContext context) { context.setTarget(new HttpTestTarget("localhost", port)); }```

aliaksandr.valadzko
2020-07-14 13:12
Hello, thanks a lot for responding! I use `JUnit4` Assume *SpringRestPactRunner* will help I used `pact-jvm-provider-junit`, will try to integrate using `pact-jvm-provider-spring`

aliaksandr.valadzko
2020-07-14 13:29
Actually getting `null` as well: ```@ContextConfiguration(classes = {PactContext.class}, loader = AnnotationConfigContextLoader.class) @RunWith(SpringRestPactRunner.class) public class PactProviderBaseTest { @Autowired protected SomeServiceMockStubs someServiceMockStubs; @Autowired protected SomeBean bean; ... }```

uladzislau_danilchyk
2020-07-15 08:14
has joined #pact-jvm

uladzislau_danilchyk
2020-07-15 08:14
Hi all! Is there any example how to write a contract for a negative scenario with 4xx errors? I faced the issue that HttpClientErrorException is thrown instead.

matt.fellows
2020-07-15 08:32
I answered in general but this is the right place to ask

uglyog
2020-07-15 09:24
HTTP clients generally throw exceptions on errors. You need to deal with that in your test

dattasai.chunduru
2020-07-15 16:49
Hi I want have a Jenkins pipeline code with shell script which looks like below ``` stage('Publish Pacts') { steps { sh './mvnw pact:publish -Dpact.consumer.version=${GIT_COMMIT} -Dpact.tag=${BRANCH_NAME}' } }``` can any one please give me the Windows bat commands for same I tried this stage('Publish Pacts') { steps { bat 'mvn pact:publish ' -Dpact.consumer.version=${GIT_COMMIT} -Dpact.tag=${BRANCH_NAME} ' } } but it is failing. can anyone please help me on this

matt.fellows
2020-07-16 02:31
this looks like Windows/Jenkins specific question. What is failing about it? Are the variables not coming through? Is maven not being executed?

dineshkr9090
2020-07-16 09:18
has joined #pact-jvm

dineshkr9090
2020-07-16 09:18
Hi Team, Please let me know which version of Java supports Pact framework. I am doing Pact contract testing but getting error like "java.util.function.supplier can not resolved" Thanks, Dinesh Kumar


os.shulyak
2020-07-16 14:50
has joined #pact-jvm

aditi.puri
2020-07-17 08:03
has joined #pact-jvm

maciej.olko
2020-07-17 09:01
has joined #pact-jvm

maciej.olko
2020-07-17 09:02
Hello, is there a way to make pact-jvm generate v2 specs?

borwoj
2020-07-17 09:39
has joined #pact-jvm

borwoj
2020-07-17 09:40
```@PactTestFor(pactVersion = PactSpecVersion.V2)``` :slightly_smiling_face:

phil.endsley
2020-07-17 13:09
Were you still looking for an example? If you have other requests working (ex: GET), they're pretty much the same, just change `.method("GET")` to `.method("POST")` The jvm workshop has examples of a GET. https://github.com/DiUS/pact-workshop-jvm#step-3---pact-to-the-rescue

dattasai.chunduru
2020-07-18 14:20
Hi Matt

dattasai.chunduru
2020-07-18 14:23
Got the Issue . The Issue is with Maven commands I changed it. It is working fine. I had another query. I know we can use mvn pact:verify is used to verify the published pact and mvn pact:publish for publishing pacts . But I had a case where I want to publish only one Pact file to Pactbroker is there any mvn command for this ?coz my scripts will generate PACT file for POST GET and DELETE when I execute them . But while publishing I want to publish only POST Pact file to PACT broker.

dattasai.chunduru
2020-07-18 15:26
Hi I'm using the below Webhook Creation for my consumer so that when ever it is changed it will trigger the Prpvider build Jenkins file from my jenkins. But When I am trying to execute it is showing error as BAD Request can anyone help me on this . The WebHook code I am using :- { "consumer": { "name": "ConsumerDataReceiver" }, "provider": { "name": "CitizenProvider" }, "request": { "method": "POST", "url": "http://localhost:8080/job/<Pbuildpipeline>/build", "headers": { "Accept": "application/json" } }, "events": [ { "name": "contract_content_changed" } ] } I am copy and pasting this code in pb:create part of my consumer. When I am clicking on Make a Request it is showing me error as 404 BAD Request . Please find the below screen shot .

antonello
2020-07-18 17:17
This is a question for the #pact-broker channel. But from the code you?ve pasted and from the error, it?s clear that the url is incorrect.

antonello
2020-07-18 17:18
Pbuildpipeline needs to be an actual value.

charu.agarwal
2020-07-18 21:39
has joined #pact-jvm

matt.fellows
2020-07-18 22:10
Are they separate files or interactions within the same file?

matt.fellows
2020-07-18 22:11
Why would you not publish all of them?

dattasai.chunduru
2020-07-20 06:00
@antonello I am not able to get by your word. May I know what is meant by Pbuildpipeline needs to be an actual value.?

dattasai.chunduru
2020-07-20 06:15
They are seperate files

dattasai.chunduru
2020-07-20 06:19
I have tried my code like this also @antonello { "consumer": { "name": "ConsumerDataReceiver" }, "provider": { "name": "CitizenProvider" }, "request": { "method": "POST", "url": "http://localhost:8080/job/Pbuildpipeline/build", "headers": { "Accept": "application/json" } }, "events": [ { "name": "contract_content_changed" } ] } but I am getting error like this

matt.fellows
2020-07-20 06:22
Hang on, you have separate files for GET, POST and DELETE? all for the same provider?

os.shulyak
2020-07-20 08:11
Hey all. I'm trying to implement Message testing with Kotlin for the Provider side. This is my code: ```@ActiveProfiles("test") @Provider("PACT_PROVIDER_PAYROLL_GATEWAY") @PactBroker(host = PACT_BROKER_URL, scheme = PACT_BROKER_SCHEME) internal class EmployeeHandlerTest(dataSource: DataSource) : BaseActionTest(dataSource) { @TestTarget val target = AmqpTarget(listOf("io.reflectoring")) private val awsProperties = mockk<AwsProperties>().apply { every { topicArn } returns "abc_topic" } private var snsClient = SnsClient(awsProperties = awsProperties) @PactVerifyProvider("message from Gateway") fun employeeMessage() { snsClient.createPublishRequest( CompanyId(1), EventName.PAYROLL_EMPLOYEE_SNAPSHOT_GENERATED, mapOf("employeeId" to 1, "entity" to "attribute") ) } }``` I've struggled with the running of the test itself. `@TestTarget` doesn't recognize that it is a test and i can't run it with IDE. If i add `@Test` annotation before `@PactVerifyProvider` , test is running, but it doesn't go to Broker and always returns true. So what is the way to make this test run properly? Googling didn't help a lot ;(

antonello
2020-07-20 08:21
It needs to be a unique identifier for the job you want to trigger.

antonello
2020-07-20 08:21
Have a look at the docs for the API of your CI system

dattasai.chunduru
2020-07-20 08:39
yeah now I am able to build the Webhook

dattasai.chunduru
2020-07-20 08:40
but it is showing as Retrying when there is a Change in Pact file but not getting verified

kristine.jetzke
2020-07-20 08:50
Maybe you?re missing a class level annotation?

kristine.jetzke
2020-07-20 08:51
The runner/extension

os.shulyak
2020-07-20 09:05
you mean this one? `@RunWith(PactRunner.class)`

os.shulyak
2020-07-20 09:08
I've got this error after trying:

abubics
2020-07-20 09:14
Does it want `PactRunner::class.java` instead?

os.shulyak
2020-07-20 09:15
@abubics

abubics
2020-07-20 09:17
Oh ok, it does want a `KClass`, sorry :sweat_smile:

abubics
2020-07-20 09:18
I don't have a Kotlin codebase handy, would you try without `.java` ? (i.e. `PactRunner::class`)

os.shulyak
2020-07-20 09:19
worked! thanks! will try to run test now :slightly_smiling_face:

os.shulyak
2020-07-20 09:21
ok, now i get this one: Here is the code: ``` @State("SomeProviderState") @PactVerifyProvider("message from Gateway") fun employeeMessage() { snsClient.createPublishRequest( CompanyId(11), EventName.PAYROLL_INTEGRATION_DISABLED, mapOf("employeeId213" to 12, "entity123" to "attribute") ) }``` and somehow i get this error: `0 - No annotated methods were found for interaction 'message from Gateway'. You need to provide a method annotated with @PactVerifyProvider("message from Gateway") on the classpath that returns the message contents.`

os.shulyak
2020-07-20 09:22
which is very strage for me because i do have method with correct annotation

os.shulyak
2020-07-20 09:23
is that something wrong with TestTarget? ```@TestTarget val target = AmqpTarget(listOf("io.reflectoring"))```

abubics
2020-07-20 09:50
Sorry, I haven't had a Kotlin provider to work on in over a year, and I haven't used this annotation workflow :< hopefully someone else can help with your specific errors :pray:

os.shulyak
2020-07-20 09:51
ok, got it. thanks for help anyway!

abubics
2020-07-20 09:51
gl ^^ I can still help with general Qs and Kotlin Qs :upside_down_face:

mark.abrahams
2020-07-20 11:50
has joined #pact-jvm

mark.abrahams
2020-07-20 11:50
Dear Pact friends, I am currently looking at the pact-jvm-server (https://docs.pact.io/implementation_guides/jvm/pact-jvm-server/)  for implementing the pact framework with a low code tool. Currently I am able to start the server and register some interactions via the /create endpoint. As mentioned in the documentation you have to define a state and path while doing so. Should I only register one interaction per /create call or can I add multiple? I noticed it works to add multiple interactions to the json however what should be the state filled in in the /create call then since the json contains multiple? And while running the tests how can I set the state the mock server should be in? For example state "user 1 does not exist" should return 404 on GET /user/1 and state "user 1 exists" should return 200 on GET /user/1. Can someone over here tell me how the pact-jvm-server is designed to be used? (register one interaction per /create call or is there some endpoint where I can specify the state the mock server should be in?) Looking forward to your answer!

mr.manish22d
2020-07-20 19:02
has joined #pact-jvm

uglyog
2020-07-20 22:52
For the method to be found, it has to be public. Try removing the `internal` from the class and add public to the method.

uglyog
2020-07-20 23:01
States are only defined, and are used when verifying the provider, not in the consumer tests were the mock server is used.

uglyog
2020-07-20 23:04
Looks like the state parameter is not actually used for anything. It may have been a key to store the pacts against.

uglyog
2020-07-20 23:05
Treat it more like a namespace

uglyog
2020-07-20 23:06
You can add as many interactions as you want, the provider state values are defined in the interactions.

mr.manish22d
2020-07-21 06:41
Hi Pact friends, I stucked with one issue, need help! Scenario: My API is Post request, which is having one token in body. I want to generate this token in provider state using provider state. In consumer test, I want to use method valuefromProviderState. But I am not getting any approach where I can add above method in my payload string. I am using Java, springboot for pact. If anyone have seen such scenario or I should follow some other approaches, please let me know. Thanks in advance. Regards, Manish

uglyog
2020-07-21 06:44
valuefromProviderState is used on the provider side when verifying the provider, not in the consumer test

uglyog
2020-07-21 06:46
It works by putting an example value that is used in the consumer test, and then the value is replaced when verifying the provider by the value returned from the provider state

mr.manish22d
2020-07-21 06:51
Hi @uglyog, thanks for your reply. Is it possible to use valuefromProviderState, if I am reading request body from a json file as string? If yes can you please share one example with me?

uglyog
2020-07-21 06:53
No, you'll need to use the Java DSL

mr.manish22d
2020-07-21 06:55
Thanks @uglyog


mark.abrahams
2020-07-21 09:01
Hi Ronald, thanks for your reply. Is there a specific reason why not to use the states at the consumer side? It would be very usefull in cases like the example I gave earlier.

uglyog
2020-07-21 23:17
The mock server is stateless, and behaves based on the interactions provided to it. For a test where you want there to be no users, you configure it to return a 404 and that is what it does. For the other test, you configure the same request to return the 200 response. What would it use the state for?

ranjanayush03
2020-07-22 06:15
has joined #pact-jvm

mark.abrahams
2020-07-22 06:15
If I register both interactions at once (get /user/1 with the no user exist state and with the user exists), I would need to be able to set the state to specify which of the two responses it should return.

mamtha.3687
2020-07-22 06:16
has joined #pact-jvm

uglyog
2020-07-22 06:19
That's why they are done in different tests

mark.abrahams
2020-07-22 06:37
So before every test you call the /create endpoint with the interaction for that test and /complete after the test is done?


mark.abrahams
2020-07-22 07:32
Ok thanks! if that is how it should be used then we do it like that

ukrainian1991
2020-07-22 08:28
has joined #pact-jvm

ukrainian1991
2020-07-22 08:58
Hi, I faced with a strange ConsumerVersionSelector behaviour (I use latest pact-jvm version and gradle plugin 4.1.6). I have several versions of Consumer mr85 mr86 mr87 and I want to verify Provider against *all* of this versions. According to docs I assigned for all of this versions the same tag "admin-client" and disable option *latest.* Here is the Gladle plugin pactVerify task config ```serviceProviders { iPaaS_CPE { ... fromPactBroker { selectors = [ new ConsumerVersionSelector("admin-client", false)] // specify your tags here. You can leave this out to just use the latest pacts }``` Also, I have tried to do this via Providers tests ```@PactBroker(host="0.0.0.0", port = "9292", consumerVersionSelectors = { @VersionSelector(tag = "admin-client", latest = "false")}) public class PactProviderPaaSTest {``` In both cases, only latest version of Consumer verified against the Provider. Could you point me how to achieve my goal?

uladzislau_danilchyk
2020-07-22 11:59
Hi all! I have the following provider test. But I need to pass config for HttpTarget retrieved from properties. I can't to move HttpTarget creation to SetUp method due to Nullpointer exception occurs. ``` @RunWith(SpringRestPactRunner.class) @TestPropertySource(locations = "classpath:application-test.properties") @Provider("My-Provider") @PactBroker(host = "${pact.broker.host}", scheme = "${pact.broker.scheme}", port = "${pact.broker.port}", authentication = @PactBrokerAuth(token = "${pact.broker.authentication.token}")) public class PactProviderVerificationTest { @Value("${test.target.protocol}") private String testTargetProtocol; @Value("${test.target.host}") private String testTargetHost; @Value("${test.target.port}") private Integer testTargetPort; @TestTarget //public Target target = new HttpTarget(testTargetProtocol, testTargetHost, testTargetPort); @State("gallery data exists") public void galleryDataExistsState() { } }```

phil.endsley
2020-07-22 12:37
```@PactBroker(host="0.0.0.0", port = "9292", consumerVersionSelectors = { @VersionSelector(tag = "admin-client", latest = "false")}) public class PactProviderPaaSTest {``` We're using this, and it's working for us... Can you try calling the pact broker endpoint that retrieves the pacts directly? ```curl --location --request POST 'http://0.0.0.0:9292/pacts/provider/[yourProvider]/for-verification' \ --header 'Content-Type: application/json' \ --data-raw '{ "consumerVersionSelectors": [{"tag": "admin-client", "latest": true}] }' ``` And also try with latest: false?

uladzislau_danilchyk
2020-07-22 12:38
Do you have any suggestions?

phil.endsley
2020-07-22 12:51
Trying to make sure I'm on the same page. Are these system properties? And you want to create `new HttpTarget` without using `@Value` (since you said you don't want to use Spring Boot)?

ukrainian1991
2020-07-22 13:12
Stranger things...

ukrainian1991
2020-07-22 13:12
Via API provided by you, everything as expected

ukrainian1991
2020-07-22 13:13
latest = false - two versions(all), latest = true only one

ukrainian1991
2020-07-22 13:14
Could you please share how you run pactVerify ?

phil.endsley
2020-07-22 13:16
We run our pact verifications with junit tests ```@PactBroker( host = pactBrokerHost, scheme = "https", consumerVersionSelectors = { @VersionSelector(tag = "develop"), @VersionSelector(tag = "prod", latest = "false") } ) @Provider("providerName")```

ukrainian1991
2020-07-22 13:23
=( the same code, verify only latest version

ukrainian1991
2020-07-22 13:23
Could you please share your version of pact broker

phil.endsley
2020-07-22 13:23
```2.57.0```

phil.endsley
2020-07-22 13:24
Your Pact Broker appears to be working, based on the api results you saw above.

ukrainian1991
2020-07-22 13:26
What about versions ```implementation 'au.com.dius.pact.consumer:junit5:4.1.6' implementation 'au.com.dius.pact.provider:junit5:4.1.6' implementation 'au.com.dius.pact.consumer:java8:4.1.6'```

phil.endsley
2020-07-22 13:27
```testImplementation("au.com.dius.pact.provider:junit5:4.1.6")```

ukrainian1991
2020-07-22 13:29
Is it possible to enable debug for pact broker? I want to see what request is comming to pact broker when I run junit tests

ukrainian1991
2020-07-22 13:29
docker logs shows nothing

phil.endsley
2020-07-22 13:30
Not sure about that one

ukrainian1991
2020-07-22 13:34
Anyway, thanks for help

phil.endsley
2020-07-22 13:35
Did your contracts change between versions?

ukrainian1991
2020-07-22 13:36
For my current config - yes

ukrainian1991
2020-07-22 13:36
One contract has 1 additional API method

ukrainian1991
2020-07-22 13:37
Also, my contract files are huge

ukrainian1991
2020-07-22 13:38
But do not thinks this is the case, because if I explicitly specify tags MR85 MR86, everything is ok

phil.endsley
2020-07-22 13:38
Hmm...I'm lost...I can see similar behavior if the consumer contract didn't change between its versions. But, that's intentional because pact de-duplicates contracts for you. Also, if that was the case, I would have expected the verified time to update for both versions, even if it was verified once (assuming they were the same)

ukrainian1991
2020-07-22 13:39
Yes, I read about this point in docs

phil.endsley
2020-07-22 13:40
Might need to wait for @bethskurrie to see if there's debug logging to enable on the pact broker side, or @uglyog to see if there's debug logging on the jvm side

ukrainian1991
2020-07-22 13:41
I created an issue earlier https://github.com/DiUS/pact-jvm/issues/1174 :smiley:

phil.endsley
2020-07-22 13:42
But I see it running all our tests like it's supposed to :confused: latest = "false" vs latest = "true"

ukrainian1991
2020-07-22 13:43
```4:31:27 PM: Executing tasks ':cleanTest :test --tests io.swagger.client.api.PactProviderPaaSTest'... > Task :cleanTest > Task :compileJava UP-TO-DATE > Task :processResources NO-SOURCE > Task :classes UP-TO-DATE > Task :compileTestJava > Task :processTestResources UP-TO-DATE > Task :testClasses > Task :test start iPaaS SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Verifying a pact between PortaBilling and iPaaS_CPE for tag porta-admin-client [from Pact Broker http://0.0.0.0:9292/pacts/provider/iPaaS_CPE/consumer/PortaBilling/version/MR86 (Tag porta-admin-client)] request correct get_devices_metainfo returns a response which has status code 200 (OK) has a matching body (OK) Verifying a pact between PortaBilling and iPaaS_CPE for tag porta-admin-client [from Pact Broker http://0.0.0.0:9292/pacts/provider/iPaaS_CPE/consumer/PortaBilling/version/MR86 (Tag porta-admin-client)] request correct get_profile_metainfo returns a response which has status code 200 (OK) has a matching body (OK) Verifying a pact between PortaBilling and iPaaS_CPE for tag porta-admin-client [from Pact Broker http://0.0.0.0:9292/pacts/provider/iPaaS_CPE/consumer/PortaBilling/version/MR86 (Tag porta-admin-client)] request generate full profile returns a response which has status code 200 (OK) has a matching body (OK) Verifying a pact between PortaBilling and iPaaS_CPE for tag porta-admin-client [from Pact Broker http://0.0.0.0:9292/pacts/provider/iPaaS_CPE/consumer/PortaBilling/version/MR86 (Tag porta-admin-client)] request get_devices_list returns a response which has status code 200 (OK) has a matching body (OK) Verifying a pact between PortaBilling and iPaaS_CPE for tag porta-admin-client [from Pact Broker http://0.0.0.0:9292/pacts/provider/iPaaS_CPE/consumer/PortaBilling/version/MR86 (Tag porta-admin-client)] request missing get_devices_metainfo returns a response which has status code 404 (OK) has a matching body (OK)```

ukrainian1991
2020-07-22 13:44
code is also pretty simple

ukrainian1991
2020-07-22 13:44
```@Provider("iPaaS_CPE") @PactBroker(host="0.0.0.0", port = "9292", consumerVersionSelectors = { @VersionSelector(tag = "porta-admin-client", latest = "false") }) public class PactProviderPaaSTest { @BeforeAll public static void enablePublishingPact() { System.setProperty("pact.verifier.publishResults", "true"); System.setProperty("pact.provider.version", "1.0.0"); System.setProperty("pact.provider.tag", "cpe_branch"); } @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); } @BeforeEach void before(PactVerificationContext context) throws MalformedURLException { context.setTarget(HttpTestTarget.fromUrl(new URL("http://0.0.0.0:10000"))); // or something like // context.setTarget(new HttpTestTarget("localhost", myProviderPort, "/")); } }```

ranjanayush03
2020-07-22 14:07
Hi team ,like I am quite new to pact but I want to integrate it with Jenkins , so can someone please help regarding this..?

phil.endsley
2020-07-22 14:29
Have you checked out the docs? They're really thorough and very well written! The FAQ section has a question specifically about Jenkins. https://docs.pact.io/faq/#is-there-a-jenkins-plugin-for-pact You can also try checking out the CI/CD workshop, which walks through setting up the whole system. It uses Travis in the workshop, but the same concepts can be applied to any CI server. https://docs.pactflow.io/docs/workshops/ci-cd/

ranjanayush03
2020-07-22 15:37
Thank you Phil.. will surely look into it..

uglyog
2020-07-22 23:05
If you enable debug level logs, you will see the requests being made to the pact broker. The easiest way to do that is to add logback to the test classpath

uglyog
2020-07-22 23:08
You can try something like `Systsem.getProperty('test.target.host')`

uglyog
2020-07-22 23:08
Pass that to the constructor. Or you can extend the HttpTestTarget class.

uladzislau_danilchyk
2020-07-23 08:11
@uglyog do you have an example on how to extend?

ukrainian1991
2020-07-23 09:02
@uglyog Hi, thanks for pointing out) It was not easy, coze I dont use log4j) However here is part of the logs: ``` [DEBUG] 2020-07-23 11:58:13.052 [Test worker] PactVerificationInvocationContextProvider - provideTestTemplateInvocationContexts called [DEBUG] 2020-07-23 11:58:13.064 [Test worker] PactVerificationInvocationContextProvider - Verifying pacts for provider 'iPaaS_CPE' and consumer 'null' [DEBUG] 2020-07-23 11:58:13.065 [Test worker] PactVerificationInvocationContextProvider - Pact source on test class: null [DEBUG] 2020-07-23 11:58:13.439 [Test worker] PactVerificationInvocationContextProvider - Pact loaders on test class: [@au.com.dius.pact.provider.junitsupport.loader.PactBroker(scheme=${pactbroker.scheme:http}, valueResolver=class au.com.dius.pact.core.support.expressions.SystemPropertyResolver, port=9292, enablePendingPacts=${pactbroker.enablePending:false}, host=0.0.0.0, includeWipPactsSince=${pactbroker.includeWipPactsSince:}, consumers=[${pactbroker.consumers:}], consumerVersionSelectors=[@au.com.dius.pact.provider.junitsupport.loader.VersionSelector(latest=false, tag=porta-admin-client)], tags=[${pactbroker.tags:}], authentication=@au.com.dius.pact.provider.junitsupport.loader.PactBrokerAuth(password=${pactbroker.auth.password:}, username=${pactbroker.auth.username:}, token=${pactbroker.auth.token:}), providerTags=[${pactbroker.providerTags:}])] [DEBUG] 2020-07-23 11:58:13.462 [Test worker] PactBrokerLoader - Loading pacts from pact broker for provider iPaaS_CPE and consumer version selectors [ConsumerVersionSelector(tag=porta-admin-client, latest=false)] [DEBUG] 2020-07-23 11:58:13.466 [Test worker] PactBrokerLoader - Authentication: None [DEBUG] 2020-07-23 11:58:13.472 [Test worker] HalClient - Fetching: / [DEBUG] 2020-07-23 11:58:13.848 [Test worker] HalClient - Fetching: / [DEBUG] 2020-07-23 11:58:13.873 [Test worker] HalClient - Fetching: http://0.0.0.0:9292/pacts/provider/iPaaS_CPE/latest/porta-admin-client [DEBUG] 2020-07-23 11:58:13.983 [Test worker] HalClient - Fetching: http://0.0.0.0:9292/pacts/provider/iPaaS_CPE/consumer/PortaBilling/version/MR86 io.swagger.client.api.PactProviderPaaSTest > pactVerificationTestTemplate(PactVerificationContext)[1] STANDARD_OUT```

ukrainian1991
2020-07-23 09:04
As I can see latest option is correctly parsed ``` [DEBUG] 2020-07-23 11:58:13.462 [Test worker] PactBrokerLoader - Loading pacts from pact broker for provider iPaaS_CPE and consumer version selectors [ConsumerVersionSelector(tag=porta-admin-client, latest=false)] <<<``` However request to brocker is the same as with latest=true ```http://0.0.0.0:9292/pacts/provider/iPaaS_CPE/latest/porta-admin-client```

paul.stitt
2020-07-23 09:24
has joined #pact-jvm

phil.endsley
2020-07-23 13:27
It's acting like your broker doesn't support the provider-pacts-for-verification endpoint :confused: This troubleshooting isn't very pretty, but not sure if there's another way... First, make sure your broker supports it. Based on the version you said you're using, and the curl commands you did earlier, I would expect it to, but I'm not sure what else to try at this point... From your broker UI, go to your API Browser, then under Links, make sure you have `provider-pacts-for-verification` I was able to put a breakpoint in the Pact code that downloads the pacts. This will be in `PactBrokerClient.fetchConsumersWithSelectors` and see if `pactsForVerification` is null.

phil.endsley
2020-07-23 13:30
If the Pact code doesn't think your broker can support the `provider-pacts-for-verification` it will use the `latest-provider-pacts-with-tag` endpoint, which is what your logs are indicating it's calling. The jvm libraries were updated a while ago to use `provider-pacts-for-verification` even if you're not using the new `consumerVersionSelectors` as long as that endpoint is supported

ukrainian1991
2020-07-23 14:37
I checked and there is no `provider-pacts-for-verification` link on Brocker. I've updated docker image from 2.57.1 to 2.58.3 and the same

phil.endsley
2020-07-23 14:41
Aha! I guess this is still a beta feature you need to opt into. In Pact Broker, you need to enable the feature with an environment variable `PACT_BROKER_FEATURES: pacts_for_verification`

phil.endsley
2020-07-23 14:48
:tada::tada::tada:

ukrainian1991
2020-07-23 14:48
Thanks) Now it's working like a charm

komeershettyvinod
2020-07-24 03:11
Hi Team

komeershettyvinod
2020-07-24 03:12
I have a very large json body that i need to verify at consumer side, I mean to say its very large , it has lot of fields to verify and having that raw json in test file is not looking clean, is there any way we can store that in json file and verify

uglyog
2020-07-24 03:17
Are you trying to verify that the consumer can process a very large JSON file? This doesn't feel like the kind of thing you use Pact to test for.

matt.fellows
2020-07-24 04:12
what are you trying to achieve? That will help us provide the best advice

matt.fellows
2020-07-24 04:13
Perhaps if you could share the test case, or a representative one, then we?ll be able to tell you what you could do

komeershettyvinod
2020-07-24 06:31
```package studentservice //import au.com.dius.pact.consumer.Pact import au.com.dius.pact.consumer.PactVerificationResult import au.com.dius.pact.consumer.groovy.InvalidMatcherException import au.com.dius.pact.consumer.groovy.Matchers import au.com.dius.pact.consumer.groovy.PactBuilder import au.com.dius.pact.model.Pact import au.com.dius.pact.model.matchingrules.DateMatcher import au.com.dius.pact.model.matchingrules.MatchingRuleGroup import au.com.dius.pact.model.matchingrules.RegexMatcher import au.com.dius.pact.model.matchingrules.TimeMatcher import au.com.dius.pact.model.matchingrules.TimestampMatcher import groovy.json.JsonSlurper //import au.com.dius.pact.core.model.matchingrules.TimestampMatcher import groovyx.net.http.RESTClient import org.junit.Test class StudentServiceConsumerPactTest { @Test void "Post User service test"() { PactBuilder student_service = new PactBuilder() // Create a new PactBuilder student_service { serviceConsumer "StudentConsumer1" // Define the service consumer by name hasPactWith "StudentProducer" // Define the service provider that it has a pact with port 9000 // The port number for the service. It is optional, leave it out to // to use a random one given('test post call for with student details') // defines a provider state. It is optional. uponReceiving('student details') // upon_receiving starts a new interaction // withAttributes(method: 'post', path: '/api/v1/student', body: '{"id":22, "firstName":"vinod", "lastName":"komeershetty"}') withAttributes(method: 'post', path: '/api/v1/student') withBody { firstName 'vinod' lastName 'komeershetty' email '' } willRespondWith( // define the response we want returned status: 200, headers: ['Content-Type': 'application/json'] ) // body: "{\"id\":2,\"firstName\":\"vinod\",\"lastUpdated\":\"2020-04-15T12:24:31Z\",\"lastName\":\"komeershetty\"}" // body: "{\"id\":2,\"firstName\":\"vinod\",\"lastUpdated\":\"2020-04-15T12:24:31Z\",\"lastName\":\"komeershetty\"}" withBody { // id(integer) firstName("vinod") lastName("komeershetty") email('') } } // Execute the run method to have the mock server run. // It takes a closure to execute your requests and returns a PactVerificationResult. PactVerificationResult result = student_service.runTest { def client = new RESTClient('http://localhost:9000/') def alice_response = http://client.post(path: '/api/v1/student', body: '{"firstName":"vinod", "lastName":"komeershetty", "email":""}', requestContentType: 'application/json',) assert alice_response.status == 200 def data = alice_response.data assert data.firstName == "vinod" assert data.lastName == "komeershetty" // assert data.lastUpdated ==~ /\d{4}\-\d{2}\-\d{2}/ assert data.email == '' } assert result == PactVerificationResult.Ok.INSTANCE // This means it is all good } }```

komeershettyvinod
2020-07-24 06:31
This is my sample test

komeershettyvinod
2020-07-24 06:32
withBody here has few fields

komeershettyvinod
2020-07-24 06:32
but ideally it has lots more 300 fields say

komeershettyvinod
2020-07-24 06:34
But i do not want to keep all the with body in the test

komeershettyvinod
2020-07-24 06:34
instead i want to make it in .json file

komeershettyvinod
2020-07-24 06:34
is there a way pact accepts .json file

komeershettyvinod
2020-07-24 06:35
instead of whole body in test

matt.fellows
2020-07-24 06:40
I don?t know groovy sorry, but what your asking seems like a pretty basic question unrelated to Pact. Presumably you can create a separate groovy file that has the Pact matchers you need, which you can simply import that into your test

uglyog
2020-07-24 06:41
Or just load the JSON file

matt.fellows
2020-07-24 06:42
That wouldn?t allow you to create specific matchers though, right?

matt.fellows
2020-07-24 06:42
(assuming you needed them)

matt.fellows
2020-07-24 06:43
Just be aware - do you actuallly need _all_ of the response values or are you importing the values simply because that?s what the provider is returning? Make sure you only include what you actually need

komeershettyvinod
2020-07-24 06:49
No i need to verify all those fields coming from provider,

matt.fellows
2020-07-24 06:50
is your consumer using them? I note that you are using `http://client.post` (perhaps that?s just to get the test moving forward)

komeershettyvinod
2020-07-24 06:54
no its a get call, i just gave example

poojashree_gopal
2020-07-24 11:06
has joined #pact-jvm

giuseppe.salvatore
2020-07-24 11:07
Hi everyone... I know this is a long shot and I haven't seen this in the documentation but

giuseppe.salvatore
2020-07-24 11:07
does PACT support contracts between SOAP enpoints?

matt.fellows
2020-07-24 11:09
It supports XML matching, and is namespace aware - so you should be able to

matt.fellows
2020-07-24 11:09
That being said, I?m not sure where it?s documented

matt.fellows
2020-07-24 11:09
https://github.com/DiUS/pact-jvm/issues/243 gives a hint, so perhaps that helps?


giuseppe.salvatore
2020-07-24 12:06
Brilliant thanks very much @matt.fellows

sidhartha.k.subudhi
2020-07-24 16:57
has joined #pact-jvm

bzifkin
2020-07-24 18:38
has joined #pact-jvm

bzifkin
2020-07-24 19:07
Hi All, I'm a software engineer for a startup in Chicago, USA and im doing a pov on pact. Im having issues publish to my pact broker (even though i had it working yesterday :disappointed: )

bzifkin
2020-07-24 19:07
I've got my broker running in docker ```postgres: image: postgres ports: - "9191:9191" volumes: - /var/lib/postgresql/data environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: password POSTGRES_DB: postgres pact_broker: image: pactfoundation/pact-broker ports: - "9292:9292" depends_on: - postgres environment: PACT_BROKER_DATABASE_USERNAME: postgres PACT_BROKER_DATABASE_PASSWORD: password PACT_BROKER_DATABASE_HOST: postgres PACT_BROKER_DATABASE_NAME: postgres PACT_BROKER_PORT: "9292"```

bzifkin
2020-07-24 19:08
in my root build.gradle i bring in and apply the plugin and also have this block: ```pact { publish { //pactBrokerUrl = "http://pact.us-central1.stage.project44.com/" //local pact broker pactBrokerUrl = "http://localhost:9292" } }```

bzifkin
2020-07-24 19:09
in build.gradle where my pact test is i just have: ``` testImplementation group: 'au.com.dius.pact.consumer', name: 'java8', version: '4.1.0' testImplementation group: 'au.com.dius.pact.consumer', name: 'junit', version: '4.1.0' testImplementation group: 'au.com.dius.pact', name: 'provider', version: '4.1.0'```

bzifkin
2020-07-24 19:10
When i run the test it passes and i see a pact file generated, however it does not showup in `localhost:9292` as it was yesterday. There are no warnings or errors telling me what may have happened

bzifkin
2020-07-24 19:11
would anyone have any thoughts?

phil.endsley
2020-07-24 19:18
Are you running the publish task after your tests? The consumer tests will generate the pact files, but you need to run the publish task separately. Should be something like `gradlew pactPublish`

phil.endsley
2020-07-24 19:19
You might also need to specify `pactDirectory = 'the/path/to/pact/files'` inside the publish block?

bzifkin
2020-07-24 19:20
from my reading of the docs the pactUrl should be equivalent to pactDirectory

bzifkin
2020-07-24 19:20
one sec

phil.endsley
2020-07-24 19:21
Also, in your post in general, you mentioned your pact verify results. Are you trying to publish the pact files (consumer), or the verification results (provider)

bzifkin
2020-07-24 19:24
pact files, excuse me

bzifkin
2020-07-24 19:25
ah i got it! im such a doofus

bzifkin
2020-07-24 19:25
my `./gradlew pactPublish` wasnt running because i had undone a change to the script i was using to run the tests

phil.endsley
2020-07-24 19:25
:tada:

bzifkin
2020-07-24 19:26
i had been tearing my hair out trying to figure out what was different haha. Thanks @phil.endsley wouldnt have checked if you hadnt mentioned it

phil.endsley
2020-07-24 19:31
> i had been tearing my hair out trying to figure out what was different Been there more times that I'd like to admit :slightly_smiling_face:

scwang
2020-07-27 01:40
has joined #pact-jvm

scwang
2020-07-27 01:41
Hi Guys, when I am running target , I always got "Request Failed - Unrecognized SSL message, plaintext connection?" , How I can make a https request ? ```@RunWith(PactRunner.class) @Provider("CM API Provider") @PactUrl(urls = {"file:///C:\\Scott\\PactProvider\\GetCampaignsConsumer-CMAPIProvider.json"}) public class ProviderTest { @State("I have a List of Campaigns") // Method will be run before testing interactions that require "with-data" state public void setupCampaign() { System.out.println("get a List of Campaigns" ); } @TestTarget // Annotation denotes Target that will be used for tests public final Target target = new HttpTarget("https", "hosr", 80); // Out-of-the-box implementation of Target (for more information take a look at Test Target section) @Before public void before() { //initialize your mocks using your mocking framework } @TargetRequestFilter public void requestFilter(HttpRequest request) { }```

uglyog
2020-07-27 01:43
Use HttpsTarget

matt.fellows
2020-07-27 01:46
why does `HttpTarget` accept a protocol if there is an HttpTarget? or is that incorrect use of the class?

uglyog
2020-07-27 01:51
PRs are welcome to fix it. But `HttpsTarget` extends `HttpTarget` so you can provide a keystore

scwang
2020-07-27 03:42
I have got 301 redirect , how can I make provide to have auto redirect ?

uglyog
2020-07-27 03:44
It should follow redirects. You might have to raise an issue for that

scwang
2020-07-27 04:12
before I raise a issue , can you please help check if I am on the right track ?

scwang
2020-07-27 04:13
```@RunWith(PactRunner.class) @Provider("CM API Provider") @PactUrl(urls = {"file:///C:\\Scott\\PactProvider\\GetCampaignsConsumer-CMAPIProvider.json"}) public class ProviderTest { HashMap<String,String> headers ; @State("I have a List of Campaigns") // Method will be run before testing interactions that require "with-data" state public void setupCampaign() { CMLogin cmLogin = new CMLogin ("xx","xx","xx"); headers = cmLogin.login(); } @TestTarget // Annotation denotes Target that will be used for tests public final Target target = new HttpTarget("http", "hostname", 80); // Out-of-the-box implementation of Target (for more information take a look at Test Target section) @Before public void before() { //initialize your mocks using your mocking framework } @TargetRequestFilter public void requestFilter(HttpRequest request) { request.addHeader("API-XSRF-TOKEN", headers.get("API-XSRF-TOKEN")); } }```

matt.fellows
2020-07-27 04:15
Is the problem that your provider isn?t responding with a 301?

scwang
2020-07-27 04:16
No, I should got 200 OK but I always got 301

scwang
2020-07-27 04:16
I am wondering how can I set pact provider to auto redirect

matt.fellows
2020-07-27 04:18
Interesting

matt.fellows
2020-07-27 04:18
why is it `301` ing?

matt.fellows
2020-07-27 04:18
I haven?t actually thought too much about that use case. Should the `301` be part of the contract? I can see arguments either way

scwang
2020-07-27 04:19
there is a nginx in front of the server

matt.fellows
2020-07-27 04:19
oh, are you pointing at a local service or one deployed somewhere?

scwang
2020-07-27 04:19
```httpclient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build(); HttpPost httpPost = new HttpPost(url);```

scwang
2020-07-27 04:19
this is what I did using my java client talk to the server

scwang
2020-07-27 04:20
I need to set setRedirectStrategy

matt.fellows
2020-07-27 04:20
gotcha

scwang
2020-07-27 04:20
any ideas ?

matt.fellows
2020-07-27 04:20
I mean, if you know the URL will always be 301'd, can you just update your consumer test to hit the right location?

matt.fellows
2020-07-27 04:21
but no, sorry (I don?t know the Java DSL very well). I suspect it?s the java verifier not following the redirect

matt.fellows
2020-07-27 04:21
perhaps there?s a way to configure that http client?

scwang
2020-07-27 04:21
my pure java client works but I as I said I need to setRedirectStrategy

scwang
2020-07-27 04:22
Yes , can you please let me know how can I set provider to auto redirect?

matt.fellows
2020-07-27 04:22
As I said, I?m not sure I was just guessing/hoping!

matt.fellows
2020-07-27 04:22
Let?s see what others think

scwang
2020-07-27 04:22
thanks

scwang
2020-07-27 04:23
should I raise a bug ?

matt.fellows
2020-07-27 04:23
but my main point was - can you not go back and update the consumer test to hit the correct URL rather than the 301 resource?

matt.fellows
2020-07-27 04:23
I mean, you now have to incur a 301 on every call - why not just update that side of the contract?

scwang
2020-07-27 04:25
I am sorry I got confused, my expected code should be 200 OK , I have no issues to use the url for functional tests

scwang
2020-07-27 04:26
the only thing I did is set http client to auto redirect , I am wondering if there is a way to set redirect in pact provider part

matt.fellows
2020-07-27 04:27
Now I?m confused. Can you please share the pact file?

matt.fellows
2020-07-27 04:30
Ron might have to step in here to clarify the verification behaviour. But your consumer test expects a 200. When the verifier runs, it goes of to hit (say) `/cm-api/clients/0A050891038CFAFC/mailings/bulk/draft`. That endpoint is returning a `301`. So it?s a different response code

matt.fellows
2020-07-27 04:30
Where is it redirecting you to?

scwang
2020-07-27 04:31
Yes , this path /cm-api/clients/0A050891038CFAFC/mailings/bulk/draft gives me 200OK

scwang
2020-07-27 04:31
api/clients/0A050891038CFAFC/mailings/bulk/draft gives me 301

matt.fellows
2020-07-27 04:31
ok, so where does it redirect you to?

matt.fellows
2020-07-27 04:32
That?s what should be in the contract in the first place

scwang
2020-07-27 04:32
Sorry I got confused, I thought when provider calls this URL it should give me 200 OK

scwang
2020-07-27 04:33
because I tried on chrome it gives me 200 OK

matt.fellows
2020-07-27 04:33
> api/clients/0A050891038CFAFC/mailings/bulk/draft gives me 301 then something else is wrong

matt.fellows
2020-07-27 04:33
you might need to look at your log files on the server and in your tests (turn on verbose/debug mode) and see what the request/response looks like

scwang
2020-07-27 04:34
it confuses me, it works on chrome dev tools

matt.fellows
2020-07-27 04:34
sure

matt.fellows
2020-07-27 04:34
there must be something different about the way the test is being setup and is causing a 301

matt.fellows
2020-07-27 04:34
maybe a header is missing etc.

matt.fellows
2020-07-27 04:35
are you the developer who manages that API? If not, might be worth a quick chat with whoever owns it to find out why it?s 301 ing

scwang
2020-07-27 04:35
cool, thanks

bruno
2020-07-27 10:18
has joined #pact-jvm

bzifkin
2020-07-27 18:24
hey all, I'm getting an error when trying to verify a pact

bzifkin
2020-07-27 18:24
I get this `Exactly one pact source should be set`

bzifkin
2020-07-27 18:25
this is my import and test class, very simple: ```import au.com.dius.pact.provider.junit.State; import au.com.dius.pact.provider.junit.target.HttpTarget; import au.com.dius.pact.provider.junit.target.Target; import au.com.dius.pact.provider.junit.target.TestTarget; import au.com.dius.pact.provider.junit.Provider; import au.com.dius.pact.provider.junitsupport.loader.PactBroker; import au.com.dius.pact.provider.spring.SpringRestPactRunner; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Import; @RunWith( SpringRestPactRunner.class ) @Provider( value = "capacity-provider-service" ) @PactBroker( host = "http://pact.us-central1.stage.xxxxx.com" ) @Import( { RibbonConfig.class, FeignClientConfig.class } ) public class CapacityProviderPactTest { // private static final String PORT = System.getenv( "CAPACITY-PROVIDER-SERVICE_TCP_9112" ); //3 @TestTarget public Target target = new HttpTarget( Integer.valueOf( PORT ) ); //4 @Autowired public CapacityProviderFeignClient capacityProviderFeignClient; //5 @State( "A request to find the capacity provider for a given id" ) public void prepareState() { } @Test public void runTest() { final CapacityProviderDto attributes = capacityProviderFeignClient.getCapacityProvider( 990029239L, 1L, 1L ); } }```

bzifkin
2020-07-27 18:25
in my build.gradle i have this ``` testImplementation group: 'au.com.dius.pact', name: 'provider', version: '4.1.0' testImplementation group: 'au.com.dius', name: 'pact-jvm-provider-spring_2.12', version: '3.5.19'```

bzifkin
2020-07-27 18:26
as far as i can tell from the docs the pactBroker annotation is the only place the source is specified so im not sure where its grabbing this second one

bzifkin
2020-07-27 20:24
is it possible that this a version issue?

bzifkin
2020-07-27 21:45
figured it out - i was importing unnecessary packages in my gradle and those brought in the wrong version of the models

uglyog
2020-07-27 23:01
@bzifkin please don't mix major versions of the pact jvm libs, they are not compatible (4.1.0 and 3.5.19)

bzifkin
2020-07-27 23:13
lesson learned haha, thank you

joaquin
2020-07-27 23:14
has joined #pact-jvm

pulgupta
2020-07-28 04:07
has joined #pact-jvm

guilherme.correa-ext
2020-07-28 22:54
has joined #pact-jvm

gcoradini
2020-07-28 22:55
has joined #pact-jvm

guilherme.correa-ext
2020-07-28 23:00
Hello i have one question regarding the publish results to pact io using java spring The scenario is i have on http://pact.io two consumers for my provider and each consumer have 2 tags wip and master i want to when i run the build in java pass a variable to tell if if have to get the pacts from the two consumers with tag that are on my parameter i try put this parameter on the PactBroker annotation on tags variable but when i run my build the application validate all tags from my consumers. My question is how can i get my provider to validate only the specific tag from all my consumers ?

uglyog
2020-07-28 23:11
How are you specifying the tag parameter? Also, are the pacts with the two tags the same?

guilherme.correa-ext
2020-07-28 23:14
```@PactBroker(scheme = "https", host = "${pactbroker.host}", authentication = @PactBrokerAuth(token = "${pactbroker.auth.token}"), tags = {"${pactbroker.tags}"})``` i have the consumer 1 with tag wip and master and a consumer 2 with tag wip and master the provider for both is my java application

uglyog
2020-07-28 23:16
And the tagged pacts, do they have different content? I.e., if I fetch the pact for wip tag and the pact for master tag, are they the same or different?

guilherme.correa-ext
2020-07-28 23:16
they are equal

uglyog
2020-07-28 23:16
Can you also let us know the versions of Pact-JVM you are using and the pact broker

guilherme.correa-ext
2020-07-28 23:18
```<dependency> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-provider-spring</artifactId> <version>4.0.10</version> </dependency>``` the pact jvm is the above and the pack broker is https://ab-inbev.pact.dius.com.au/

uglyog
2020-07-28 23:35
Can you try where the content is different? The broker links everything to pact file versions, so it may be returning all the tags that are linked to that version of the pact file.

guilherme.correa-ext
2020-07-28 23:36
the content of the pact are the same but the version for each tag is different

javier.molina
2020-07-29 08:43
has joined #pact-jvm

javier.molina
2020-07-29 09:08
Hello! I just https://stackoverflow.com/questions/63149128/how-to-verify-stringified-json-in-pact, and I hope some of you in here will be able to answer it. Thank you!

daniele.scillia
2020-07-29 09:34
has joined #pact-jvm

marco.dallagiacoma
2020-07-29 09:41
has joined #pact-jvm

jan.krejci
2020-07-29 12:29
has joined #pact-jvm

josue.boix
2020-07-29 13:32
Hello everybody! I?m struggling to create a contract for a POST with multi-part form data. I managed to do it in the past using `.withFileUpload` when having just a file. This time I have a file with a few other params, and I can?t find any good examples for such thing. Any ideas?

josue.boix
2020-07-29 14:27
I found this. I guess this feature is not yet supported: https://github.com/DiUS/pact-jvm/issues/668

phil.endsley
2020-07-30 01:40
I think it might already be working how you want it to. If you have pacts that are identical in content, your verification results are applied to all of those, because behind the scenes, they're the same. This is a feature of pact broker. Or, are you seeing each tag tested against in your build logs? I don't think that should be happening, because pact broker should de-duplicate any identical pacts when the provider fetches them for testing

ivan.lombardiborgia
2020-07-30 06:52
has joined #pact-jvm

fernando.martin
2020-07-30 11:39
Hey, @phil.endsley Thanks for you attention, @uglyog helped us and the behavior was exactly what you said about the identical content :slightly_smiling_face: Thanks, all!

matias.waterloo
2020-07-30 12:18
has joined #pact-jvm

amer.mohammed
2020-07-30 12:28
has joined #pact-jvm

amer.mohammed
2020-07-30 12:32
Hi there! I'm trying to verify the pact at producer end. I'm using JUnit5, Spring Boot and ```au.com.dius.pact.provider:junit5:4.1.6``` I've to add some authentication headers before the request is sent. I've got to know that TargetRequestFilter is the way to achieve it. But when I tried this, the request still missing the headers I'm trying to add. I have asked this on here - https://stackoverflow.com/questions/63118545/pact-jvm-provider-junit5-spring-unable-to-add-authorization-headers Can you please point out what I'm doing wrong? Thanks!

matias.waterloo
2020-07-30 19:43
Hi! I have a question regarding junit provider tests and WIP pacts. Is it possible to configure the test to validate against the latest version of a given fix tag and any WIP pacts (doesn?t matter the tag)? I tried the next example but it didn?t work. The broker has a WIP pact (created today) with tag feat-x and I?m trying to run the provider test with this config ```pactbroker.tags = "develop" pactbroker.enablePending = true pactbroker.providerTags = feat-x pactbroker.includeWipPactsSince = "2020-07-01" (since last month)``` Any ideas how to make this work? is it possible? Thanks!

phil.endsley
2020-07-30 19:53
Yes, this is possible. The only thing that looks suspicious is the `pactbroker.providerTags = feat-x` line. `pactbroker.providerTags` should be set to the tag(s) of the current provider branch that is being built. Based on what you have above, this would mean the branch you're running on the provider side is tagged with `feat-x`. In order for WIP Pacts to be picked up by your provider tests, Pact Broker must have at least one version with the given provider tag already published. If the `feat-x` does not exist for your provider in Pact Broker, it will not pick up any WIP pacts.


matias.waterloo
2020-07-30 21:13
I could make it work. Thanks!!

amer.mohammed
2020-07-31 07:11
It worked! :smile: Many thanks Phil!

bruno.penha
2020-08-03 08:21
has joined #pact-jvm


bzifkin
2020-08-03 21:07
I'm having issues publishing to the pact broker when the verification actually runs....however if creating provider state fails then the results are published

bzifkin
2020-08-03 21:08
i put a breakpoint in InteractionRunner.java where it checks to see if publishing is enabled and when i break method that creates the provider state (adding a field to the object that should be null) then its set to publish the results

bzifkin
2020-08-03 21:08
But when the provider state method works (field is actually null) it is somehow not enabled anymore

bzifkin
2020-08-03 21:08
i have tried to set it w/ this in the gradle command line args `-Dpact.verifier.publishResults=true`

bzifkin
2020-08-03 21:09
also in other places that properties can be set, but no luck.....makes no sense that it would be set in one and not the other though. Please let me know if you have any insite

uglyog
2020-08-03 23:08
What version of Pact-JVM are you using?

uglyog
2020-08-03 23:09
For Gradle, you need to use `-P` not `-D`

scwang
2020-08-04 05:33
Hi, I am wondering , does pact provider side support custom verification, we do not want to everything in the contract. is there anyway to do customized verification ?

matt.fellows
2020-08-04 05:39
what do you mean, sorry?

scwang
2020-08-04 05:55
I am wondering if I can control the provider verification ?

scwang
2020-08-04 05:56
in our contract there are some fields which are constantly changed (like timestamp ), I am wondering if there is a way to ignore these field

antonello
2020-08-04 06:07
I think you need to consider using matchers in order to verify certain fields by type rather than by value. Have a look here https://docs.pact.io/getting_started/matching/

scwang
2020-08-04 06:09
thanks

matt.fellows
2020-08-04 06:31
> in our contract there are some fields which are constantly changed (like timestamp ), I am wondering if there is a way to ignore these field ignoring a field is definitely a smell. If your consumer needs a field, then ignoring it is a recipe for disaster and removes the value of Pact tests in the first place.

matt.fellows
2020-08-04 06:32
But as Anto points out, matchers will make this less painful

ukrainian1991
2020-08-04 07:03
Hi, could you please point me to the docs or examples of using Pact Matchers. I have checked the official docs (https://docs.pact.io/implementation_guides/jvm/matching) and it's hard to understand) I have a huge request and it has one variable. I need to match this request for stubbing. Maybe someone has useful links. Thanks


matt.fellows
2020-08-04 07:09
perhaps if you could share a code example

ukrainian1991
2020-08-04 07:18
```.uponReceiving("request generate full profile") .path("/cpe/generate_profile/200") .method("POST") .headers(headersRequest) .body(Resources().getContent("request/generate_profile_full.json")) .willRespondWith() .status(200) .headers(headersResponse) .body(Resources().getContent("response/generate_profile_full.json")) .toPact()``` request/generate_profile_full.json raw json where in "ports info" i have one non static id

ukrainian1991
2020-08-04 07:19
As you can see "profile_data" is a huge key-value array. But it static

ukrainian1991
2020-08-04 07:24
code is on Kotlin

scwang
2020-08-04 08:21
thanks

ukrainian1991
2020-08-04 12:09
Please help with minArrayLike case. Koltin, pact-jvm 4.1.6. I want to match a json request with 13000 items in array. I use the following ``` newJsonObject { stringValue("api_version", "v1") minArrayLike("profile_data", 13191) { stringType("value", "60") stringType("name", "account.35.max_time") } ...``` Test fails with BodyMismatch ```BodyMismatch: Expected form post parameter '{"name":"account.35.reg_failed_retry_max_time","profile_data":[{},{},{},{}...{},{},{},{},{}],"api_version":"v1","value":"60"}' but was missing```

ukrainian1991
2020-08-04 12:10
Here is the raw json ```{ "api_version": "v1", "profile_data": [ { "value": "0", "name": "account.9.timeout_fwd.enable" }, { "value": "0", "name": "account.95.nat.rport" } ... ] }```

william.isaksson795
2020-08-04 13:15
has joined #pact-jvm

bzifkin
2020-08-04 14:23
Yes i tried it w/ that as well

bzifkin
2020-08-04 14:24
```testImplementation group: 'au.com.dius', name: 'pact-jvm-provider-spring_2.12', version: '3.5.23'```

bzifkin
2020-08-04 19:06
hey everyone, still trying to get my provider to publish verification results to the broker. Before was trying to do via running the tests, wasnt working, even when i had `-Ppact.verifier.publishResults=true` set in various places. Now trying to do it w/ the plain old `./graldew pactVerify` but running into issues there as well

bzifkin
2020-08-04 19:08
```pact { serviceProviders { "p44-capacity-provider-service" { protocol = 'http' host = 'http://pact.us-central1.stage.project44.com/' port = 80 path = '/' hasPactWith('carrier-service') { // currently supports a file path using file() or a URL using url() pactSource = url('http://pact.us-central1.stage.xxxxxx.com/pacts/provider/p44-capacity-provider-service/consumer/carrier-service/latest') } } } }```

bzifkin
2020-08-04 19:10
suspect im using the wrong url....it should be pointing to the contract itself correct?

bzifkin
2020-08-04 19:11
that url puts me here:

bzifkin
2020-08-04 19:12
i think its the wrong url because of the complaint it gives me: ```1) Verifying a pact between carrier-service and p44-capacity-provider-service - A request to find the capacity provider for a given id Given Find a Capacity Provider 1.1) StatusMismatch: expected status of 200 but was 404 1.2) HeaderMismatch: Expected 'application/hal+json' to match 'application/json(;\s?charset=[\w\-]+)?' 1.3) BodyTypeMismatch: Expected a response type of 'application/json' but the actual type was 'application/hal+json'``` I've tried a bunch of other urls but those dont really get me anywhere either

bzifkin
2020-08-04 21:18
============ ok switching gears a bit =============

bzifkin
2020-08-04 21:20
whats the benefit of using the gradle plugin vs the junit/spring plugin to verify pacts?

bzifkin
2020-08-04 21:22
does one offer more flexibility than the other? slash would one be better suited to use in a CI/CD pipeline? my thought is that the gradle plugin would be better but im not sure

francis.lobo
2020-08-04 22:48
has joined #pact-jvm

uglyog
2020-08-04 22:55
That is a lot of items. Is there a reason you are testing that with Pact and not a unit test?

uglyog
2020-08-04 22:58
@bzifkin for unit tests, you need the system property set for the unit test process. The `-P` parameter sets the value for the Gradle process, but when the tests are run. Gradle will start a new JVM process to run the tests. You need to apply the system property on the test task.

uglyog
2020-08-04 23:00
Different people have different options on this. With unit tests you have more control, and can easily mock out other collaborators in the test.

francis.lobo
2020-08-05 06:11
Hello folks, I am quite new to JVM/gradle world I am trying to debug a issue when running pact provider tests. Is there a way to make the logging a bit verbose (like DEBUG or INFO)? I just can't figure out how to do it in Gradle world. I couldn't find anything related to this in the Pact docs either

uglyog
2020-08-05 06:26
For Gradle tasks, `-d` option sets debug level logging, and `-i` info level

uglyog
2020-08-05 06:26
If you are using JUnit tests, you will need to configure SLF4J to set the log level

ukrainian1991
2020-08-05 06:30
Our monolithic app sends request to our microservice. So I want to verify contract. Huge request contains list of parameters. Based on these parameters microservice generates profile and return it in response.

uglyog
2020-08-05 06:36
But why do you need to test with 13000 items? Won't they be all the same? The idea with Pact tests is to test the shape of things are correct. You're using `minArrayLike`, which will check all the values from the provider match the example value. So you really only need one in your consumer test.

ukrainian1991
2020-08-05 06:37
Maybe you could give me an advice how to workaroud this. For example? Is it possible to specify part of the body as raw Json (fille) - list of params. And the part with variables as matchers

uglyog
2020-08-05 06:40
No, the DSL doesn't have anything like that

ukrainian1991
2020-08-05 06:41
In fact, all 13000 parameters are unique and I want just one test and check contract based on full profile generation

ukrainian1991
2020-08-05 06:41
Seems the only way is template strings for raw json with variables substitution

uglyog
2020-08-05 06:42
This doesn't feel like a thing to use Pact for. Something like JSON Schema might be a better option.

ukrainian1991
2020-08-05 06:50
I've thought about schema... But I found PACT more applicable to this workflow. Maybe I end up with json schema) Thanks for your time

tim.den.dulk
2020-08-05 08:07
has joined #pact-jvm

uladzislau_danilchyk
2020-08-05 14:09
@uglyog I have found following solution. You can define method with `@PostConstruct` and inside of it create `HttpTarget` instance.

bzifkin
2020-08-05 17:41
yeah, i realized i had to set it in the test gradle block....i used the intellij runner for the gradle task which allows you to add properties for the gralde process, which i thought would be the same but it isnt :confused:

bzifkin
2020-08-05 17:41
thank you, good to know

bzifkin
2020-08-05 17:45
it seemed like it may be easier to do the versioning stuff for the provider through the gradle plugin but maybe not

francis.lobo
2020-08-05 21:09
thanks @uglyog

matt.fellows
2020-08-06 11:40
Mike just so we?re clear

matt.fellows
2020-08-06 11:41
if the shape of the data is the same (i.e. it?s always a `name` and `value` ) then Pact is best suited to saying ?for this list of items, do they all have those two properties and are they the correct type - such as a string or a number?. If you need to check specific values for 13,000 items, this is a bit more of a functional test which Pact is not designed for

matt.fellows
2020-08-06 11:42
Pact is trying to catch issues where a structural change in an API will break one of the API collaborators

matt.fellows
2020-08-06 11:42
Looking at the example you shared, there?s no reason why you couldn?t use Pact for it at all

matt.fellows
2020-08-06 11:42
?but if you can reduce the data it validates it will probably be helpful in making the test suites run faster!

aditi.puri
2020-08-07 05:42
@aditi.puri has left the channel

ranjanayush03
2020-08-07 08:43
This is my Jenkins log

ranjanayush03
2020-08-07 08:43
Unable to run the command ./gradlew pactVerify in the Jenkins step

ranjanayush03
2020-08-07 08:45
Actually the service needs to be up for running the test cases but I tried providing it as a part of integration test like this .

ranjanayush03
2020-08-07 08:45
I am providing the @springboottest annotation also..

abubics
2020-08-07 08:46
Pretty sure `gradle` ran fine. A warning says "there is no stateChange URL".

abubics
2020-08-07 08:47
And connection refused

abubics
2020-08-07 08:48
Could I suggest not taking photos of the screen, but copying & pasting your logs and/or code into code blocks or snippets?

ranjanayush03
2020-08-07 08:48
Yup I guess so I tried running ./gradlew pactVerify command.. in the build stages. But the issue I think that I have not started the server..

ranjanayush03
2020-08-07 08:49
From next time I will keep that in mind..

abubics
2020-08-07 08:51
There are code samples to help you start up and shut down the provider using gradle, if that's what you need. You shouldn't have to manually start & stop a separate process by hand :)

ranjanayush03
2020-08-07 08:52
The startproviderTask and terminateProvidertask

ranjanayush03
2020-08-07 08:52
I was going through the documents I saw these two steps to run..

ranjanayush03
2020-08-07 08:56
Is this the one you are talking about ?

abubics
2020-08-07 09:08
that's right :slightly_smiling_face:

abubics
2020-08-07 09:08
I feel like the annotations you're using in the provider code shouldn't need the gradle integration, though

abubics
2020-08-07 09:09
I always use gradle, and no annotations, so I can't really help you beyond this amount of hinting :pray:

sidhartha.k.subudhi
2020-08-10 14:17
I am getting "PactMismatchesException" error. Need help in this. here is the code: ```public class Post_AddPetType { private final String PROVIDER = "pet_petType_provider"; private final String CONSUMER = "pet_petType_consumer"; @Rule public PactProviderRuleMk2 mockProvider = new PactProviderRuleMk2(PROVIDER, "localhost", 8081, this); @Pact(provider=PROVIDER, consumer=CONSUMER) public RequestResponsePact addPetType(PactDslWithProvider builder) { return ConsumerPactBuilder .consumer(CONSUMER) .hasPactWith(PROVIDER) .uponReceiving("a POST request to create a pet type.") .path(String.format(Constants.PETTYPE))// GET http://localhost:9966/petclinic/api/pettypes .method("POST") .willRespondWith() .status(200) .matchHeader("Content-Type", "application/json; [Cc]harset=UTF-8") //; [Cc]harset=UTF-8 // .body(new PactDslJsonBody() //// .object() // .integerType("id",8) // .stringValue("name", "Hatch") // .closeObject()) .body("{\n" + " \"id\": 8,\n" + " \"name\": \"Hatch1\"\n" + "}") .toPact(); } @Test @PactVerification(value=PROVIDER, fragment = "addPetType") public void shouldBeAbleToAddPetType() { given() .baseUri("http://localhost:8081") .header("Content-Type", "application/json; [Cc]harset=UTF-8") // .header("Accept-Encoding","gzip, deflate, br") // .pathParam("id",8) .body("{\n" + "\"id\": 8,\n" + "\"name\": \"Hatch1\"\n" + "}") .post("/petclinic/api/pettypes") .then() .assertThat() .statusCode(200); } }```

sidhartha.k.subudhi
2020-08-10 14:17
Error message is: java.lang.AssertionError: Pact Test function failed with an exception, possibly due to Mismatches(mismatches=[UnexpectedRequest(request= method: POST path: /petclinic/api/pettypes query: [:] headers: [Accept-encoding:[gzip,deflate], Accept:[*/*], Connection:[Keep-Alive], Host:[localhost:8081], User-agent:[Apache-HttpClient/4.5.5 (Java/1.8.0_144)], Content-type:[text/plain; charset=ISO-8859-1], Content-length:[29]] matchers: MatchingRules(rules={}) generators: Generators(categories={}) body: PRESENT({ "id": 8, "name": "Hatch1" }))]) at http://au.com.dius.pact.consumer.junit.JUnitTestSupport.validateMockServerResult(JUnitTestSupport.kt:54) at http://au.com.dius.pact.consumer.BaseProviderRule.validateResult(BaseProviderRule.java:175) at http://au.com.dius.pact.consumer.BaseProviderRule$1.evaluate(BaseProviderRule.java:80) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53) Caused by: java.lang.AssertionError: 1 expectation failed. Expected status code <201> but was <500>. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:80) at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:74) at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:237) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:249) at io.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure.validate(ResponseSpecificationImpl.groovy:494) at io.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure$validate$1.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:127) at io.restassured.internal.ResponseSpecificationImpl.validateResponseIfRequired(ResponseSpecificationImpl.groovy:656) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:43) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:190) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:58) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:156) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:168) at io.restassured.internal.ResponseSpecificationImpl.statusCode(ResponseSpecificationImpl.groovy:125) at io.restassured.specification.ResponseSpecification$statusCode$0.callCurrent(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:156) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:168) at io.restassured.internal.ResponseSpecificationImpl.statusCode(ResponseSpecificationImpl.groovy:133) at io.restassured.internal.ValidatableResponseOptionsImpl.statusCode(ValidatableResponseOptionsImpl.java:119) at com.sap.icn.mlp.consumer.petClinic.Post_AddPetType.shouldBeAbleToAddPetType(Post_AddPetType.java:62) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at http://au.com.dius.pact.consumer.BaseProviderRule.lambda$runPactTest$2(BaseProviderRule.java:161) at http://au.com.dius.pact.consumer.BaseMockServer.runAndWritePact(MockHttpServer.kt:181) at http://au.com.dius.pact.consumer.ConsumerPactRunnerKt.runConsumerTest(ConsumerPactRunner.kt:13) at http://au.com.dius.pact.consumer.BaseProviderRule.runPactTest(BaseProviderRule.java:159) at http://au.com.dius.pact.consumer.BaseProviderRule.access$100(BaseProviderRule.java:23) at http://au.com.dius.pact.consumer.BaseProviderRule$1.evaluate(BaseProviderRule.java:79) ... 15 more Picked up JAVA_TOOL_OPTIONS: -Djava.vendor="New Oracle" Process finished with exit code -1

joao
2020-08-10 15:48
On @Pact, you are defining the body as a response, not as an expected request; whereas on the @Test you sending a JSON body on the request.

bzifkin
2020-08-10 16:27
hey all - all of our provider projects are spring boot and dockerized, even so some of them take upwards of 10 minutes to build

bzifkin
2020-08-10 16:29
Right now the verification tests are in the integration tests module, meaning the full docker image gets built and run....I was thinking about just making a separate module that just has the db in the docker image since that would speed stuff up a bit

bzifkin
2020-08-10 16:29
I was curious if others had had this issue and what they did to solve it

wesleythomaswilliams
2020-08-10 21:32
@bzifkin All of our tests run at the unit test phase of our build so they're one of the first things to run.

bzifkin
2020-08-10 21:34
thanks @wesleythomaswilliams...does the app have to build at that time?

wesleythomaswilliams
2020-08-10 21:37
Yeah, we haven't separated the tests out into a separate jenkins job or anything, so they're part of a full build of the provider service. We have connectivity issues preventing us from having consumer builds trigger provider builds right now, so speed of verification isn't a priority right now. If/when the connectivity issue is solved, then I might look to separate it.

bzifkin
2020-08-10 21:53
ok gotcha, yeah we're pretty early in our implementation as well, a lot of our consumers have multiple providers....looks like we're just gonna have to be ok w/ the fact that stage of the pipeline will only be as fast as the slowest provider

scwang
2020-08-11 00:54
Hey I am wondering how to verify a dynamic json key in pact ?

matt.fellows
2020-08-11 00:56
Ah, that?s a good question. I?m not sure if JVM supports it or not, but this issue is relevant: https://github.com/pact-foundation/pact-specification/issues/47


scwang
2020-08-11 00:58
Ye, I have looked trough the this and tried workaround but it does not work for me , do you have any idea on how can I develop a workaround for the issue ?

matt.fellows
2020-08-11 00:58
I don?t, sorry

scwang
2020-08-11 00:59
let me check, thanks

scwang
2020-08-11 01:03
does js pact support this ?

matt.fellows
2020-08-11 01:18
no it doesn?t

scwang
2020-08-11 04:54
I am wondering are you going to add the feature for V4 ?

matt.fellows
2020-08-11 05:08
that?s the plan

scwang
2020-08-11 05:19
Thanks a lot

matt.fellows
2020-08-11 05:31
Also, if you need it, please vote on the issue. It helps us prioritise

vit.barabash
2020-08-11 06:52
has joined #pact-jvm

ivangsa
2020-08-11 08:51
Hi, versions 4.1.x for pact-jvm-provider-maven are published to maven-central? I can only find up to version 4.0.10.... We would like to use functionality from this PR https://github.com/DiUS/pact-jvm/pull/1135 which is posterior..

rafael.espillaque
2020-08-11 09:25
the groupId and artifactId changed, look for: ```<groupId>au.com.dius.pact.provider</groupId> <artifactId>junit5</artifactId> <version>4.1.6</version>```

francislainy.campos
2020-08-11 14:04
Hi, sorry for the simple question but struggling to find a sample on how to set a contract with specific params sent to a POST api? Most samples I see all use GET with no need for this so a bit stuck at the moment.

francislainy.campos
2020-08-11 14:05
Will open a thread with what I have so far. Thank you.

francislainy.campos
2020-08-11 14:06
```@ExtendWith(PactConsumerTestExt.class) public class PACTConsumerEdUiCrsTest { Map<String, String> headers = new HashMap<>(); String getRecommendations = "/api/v1/getRecommendations"; @Pact(provider = "CRS-SERVICE", consumer = "Ed UI") public RequestResponsePact createPact(PactDslWithProvider builder) { headers.put("Content-Type", "application/json"); .maxArrayLike("skills", 1) .stringType("id", "7810fb5f-a45d-41af-baeb-ac08dd10546b") .stringType("title", "Read Words with Consonant \\\"r\\\" /r/") .stringType("skillRecommendationReason", "Progressing: this student is progressing towards proficiency with the following standards and will benefit from additional instructions and practice.") .array("students") .closeArray() .eachLike("contentRecommendations") .stringType("identifier", "l_479ac4a4-6fc3-4323-9609-ca614c672016_ac54bcae-235c-4d50-a5d8-bca2767dabe7") .decimalType("score", 1.2450236288128311) .array("contentRecommendationReason") .string("The next items in the TOC matching the skill") .closeArray() .closeArray() .closeArray(); return builder .uponReceiving("getRecommendations") .path(getRecommendations) .method("POST") .headers(headers) .body("{\"hello\": \"harry\"}") .willRespondWith() .status(200) .body(body) .toPact(); } @Test @PactTestFor(providerName = "CRS-SERVICE", port = "8080") public void runTest() { //Mock url RestAssured.baseURI = "http://localhost:8080"; Response response = RestAssured .given() .headers(headers) .when() .post(getRecommendations); assert (response.getStatusCode() == 200); } }```

francislainy.campos
2020-08-11 14:07
And need to set this as for the params to have a valid request.

francislainy.campos
2020-08-11 14:07
``` {"discipline": "ED18_RLA","programs": ["ELA_IR_G1_NA"], "sectionId": "357e6a22-ea67-458f-8d1a-7e15ec8d4cce" }```

francislainy.campos
2020-08-11 14:15
Ah, nevermind. Thanks. I think I figured out what I was missing. It seems I need to give the params both here ```return builder .uponReceiving("getRecommendations") .path(getRecommendations) .method("POST") .headers(headers) .body(" { \"discipline\": \"ED18_RLA\", \"programs\": [\"ELA_IR_G1_NA\"], \"sectionId\": \"357e6a22-ea67-458f-8d1a-7e15ec8d4cce\" }") .willRespondWith() .status(200) .body(body) .toPact();```

francislainy.campos
2020-08-11 14:15
And here

francislainy.campos
2020-08-11 14:15
```Response response = RestAssured .given() .headers(headers) .when() .body(" { \"discipline\": \"ED18_RLA\", \"programs\": [\"ELA_IR_G1_NA\"], \"sectionId\": \"357e6a22-ea67-458f-8d1a-7e15ec8d4cce\" }") .post(getRecommendations);```

francislainy.campos
2020-08-12 07:15
Hi, good morning. Sorry, me again. I have this json response that starts with an array rather than an object. However, my contract gets generated with two square brackets rather than only the one for the root. Tried a few combinations using either object or array but they're all failing on me if I can get some help to see what I'm missing please. Thanks very much. ```DslPart body = new PactDslJsonArray() .maxArrayLike(1) .stringType("studentId", "1cd1bfa6-87a7-4bea-8025-fb7cd159f1fb") .eachLike("skills", 2) .stringType("id", "544c07c1-75b4-4a9b-b6fe-50f5a0708457") .stringType("name", "") .booleanType("primary", true) .closeArray() .closeArray();``` This is what I've been getting for my contract. ```"body": [ [ { "studentId": "1cd1bfa6-87a7-4bea-8025-fb7cd159f1fb", "skills": [ { "name": "", "id": "544c07c1-75b4-4a9b-b6fe-50f5a0708457", "primary": true }, { "name": "", "id": "544c07c1-75b4-4a9b-b6fe-50f5a0708457", "primary": true } ] } ] ],```

uglyog
2020-08-12 07:24
`new PactDslJsonArray()` creates a new array, and then `.maxArrayLike(1)` adds a new array as the first item

francislainy.campos
2020-08-12 07:25
Hi uglyog, thanks for reaching out. Yes, however, if I remove the .maxArray piece it complains to me on the next line and it won't compile.

uglyog
2020-08-12 07:25
Use `PactDslJsonArray.arrayMaxLike(1)` (static method)

uglyog
2020-08-12 07:26
That just creates a new array

uglyog
2020-08-12 07:27
But, with `.maxArrayLike(1)` removed it should work

uglyog
2020-08-12 07:28
```DslPart body = new PactDslJsonArray() .stringType("1cd1bfa6-87a7-4bea-8025-fb7cd159f1fb") .eachLike("skills", 2) .stringType("id", "544c07c1-75b4-4a9b-b6fe-50f5a0708457") .stringType("name", "") .booleanType("primary", true) .closeArray();```

francislainy.campos
2020-08-12 07:29
Thanks. Sure. Let me try it here.

uglyog
2020-08-12 07:29
Use the static method, it will do what you want

francislainy.campos
2020-08-12 07:32
Maybe I need to sit on this a bit more but now it's giving me a null error.

francislainy.campos
2020-08-12 07:33
When I try this instead.

francislainy.campos
2020-08-12 07:33
```DslPart body = new PactDslJsonArray() .stringType("1cd1bfa6-87a7-4bea-8025-fb7cd159f1fb") .eachLike("skills", 2) .stringType("id", "544c07c1-75b4-4a9b-b6fe-50f5a0708457") .stringType("name", "") .booleanType("primary", true) .closeArray();```

francislainy.campos
2020-08-12 07:33
It gives me this different message.

francislainy.campos
2020-08-12 07:35
And if I change to my studentId key I get this.

francislainy.campos
2020-08-12 07:36
And without the studentId key and using empty eachlike it compiles but the contract would be missing this key.

francislainy.campos
2020-08-12 07:40
```import au.com.dius.pact.consumer.dsl.*; import au.com.dius.pact.consumer.junit5.PactConsumerTestExt; import au.com.dius.pact.consumer.junit5.PactTestFor; import au.com.dius.pact.core.model.RequestResponsePact; import au.com.dius.pact.core.model.annotations.Pact; import io.restassured.RestAssured; import io.restassured.response.Response; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import java.util.HashMap; import java.util.Map; @ExtendWith(PactConsumerTestExt.class) public class PACTConsumerCrsSgmTest { Map<String, String> headers = new HashMap<>(); String recommendedSkills = "/recommendedSkills"; @Pact(provider = "SGM", consumer = "CRS-SERVICE") public RequestResponsePact createPact(PactDslWithProvider builder) { headers.put("Content-Type", "application/json"); // DslPart body = PactDslJsonArray.arrayMaxLike(1) //// .maxArrayLike(1) // .stringType("studentId", "1cd1bfa6-87a7-4bea-8025-fb7cd159f1fb") // .eachLike("skills", 2) // .stringType("id", "544c07c1-75b4-4a9b-b6fe-50f5a0708457") // .stringType("name", "") // .booleanType("primary", true) // .closeArray() // .closeArray(); DslPart body2 = new PactDslJsonArray() .maxArrayLike(1) .stringType( "studentId", "1cd1bfa6-87a7-4bea-8025-fb7cd159f1fb") .eachLike("skills", 2) .stringType("id", "544c07c1-75b4-4a9b-b6fe-50f5a0708457") .stringType("name", "") .booleanType("primary", true) .closeArray(); return builder .uponReceiving("recommendedSkills") .path(recommendedSkills) .method("POST") .headers(headers) .body("{ \"disciplineCode\": \"ED18_RLA\", \"studentIds\": [\"1cd1bfa6-87a7-4bea-8025-fb7cd159f1fb\"]}") .willRespondWith() .status(200) .body(body2) .toPact(); } @Test @PactTestFor(providerName = "SGM", port = "8080") public void runTest() { //Mock url RestAssured.baseURI = "http://localhost:8080"; Response response = RestAssured .given() .headers(headers) .when() .body("{ \"disciplineCode\": \"ED18_RLA\", \"studentIds\": [\"1cd1bfa6-87a7-4bea-8025-fb7cd159f1fb\"]}") .post(recommendedSkills); assert (response.getStatusCode() == 200); } }```

francislainy.campos
2020-08-12 07:40
This is my whole file as of now.

francislainy.campos
2020-08-12 07:41
This piece worked. ```DslPart body = PactDslJsonArray.arrayMaxLike(1) .stringType("studentId", "1cd1bfa6-87a7-4bea-8025-fb7cd159f1fb") .eachLike("skills", 2) .stringType("id", "544c07c1-75b4-4a9b-b6fe-50f5a0708457") .stringType("name", "") .booleanType("primary", true) .closeArray();```

francislainy.campos
2020-08-12 07:42
Had to remove the second closeArray that was there.

francislainy.campos
2020-08-12 07:42
Thanks a lot @uglyog. Your help is greatly appreciated. Have a lovely day.

amer.mohammed
2020-08-12 09:09
Hello, I'm going through the GitHub documentation and some of the issues reported. I've noticed that they have some broken links to the examples under discussion, like the one mentioned below. Can you please let me know if the examples are gone from the repository or renamed or the path is changed? Thanks! https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider-junit#example-of-amqp-message-test


javier.molina
2020-08-13 13:04
Hi, I?m following the instructions from https://docs.pact.io/implementation_guides/jvm/provider/maven/ to perform provider verification, but i have the requirement of publishing mutiple tags. As far as I can see, it only supports `-Dpact.provider.tag` variable, and this is only for a single value. Can I do something to add more than one tag? Thank you!

uglyog
2020-08-13 22:50
Can you raise an issue for that at the Github project

javier.molina
2020-08-14 06:33
:ok_hand:

ivangsa
2020-08-14 07:09
Hi, using PactProviderRule with junit... after upgrading from version 4.0.5 to version 4.1.7 *mockServer is null and not started* anymore... I'm missing something on this upgrade or shall investigate this as a bug?

andrea.spina
2020-08-14 07:36
has joined #pact-jvm

ivangsa
2020-08-14 07:58
sorry, it's ok... a typo slid through on provider name doing some quick test

amer.mohammed
2020-08-14 08:03
Thanks!

ukrainian1991
2020-08-14 11:54
@matt.fellows Thanks for your response. I've read and watched a lot for pact and json schema approaches. I agree that checking exact values an overhead for contract testing, but in my case all these parameters are static(dictionary). Want to try it out how it would work in a strict manner

matt.fellows
2020-08-14 13:19
We can't stop you :wink:

tom.wilson
2020-08-14 19:20
has joined #pact-jvm

ziadtawfeek05
2020-08-17 08:16
has joined #pact-jvm

tomas.bruhn
2020-08-17 13:33
has joined #pact-jvm

tomas.bruhn
2020-08-17 13:42
Hi, is it possible to specify the identity of a queue when writing message pacts? Basically the client stating which queue should receive the message so the provider knows where to produce the message.

bzifkin
2020-08-17 20:56
is it possible to set tags/versions of consumers when running `pactPublish` in the gradle plugin? I know pactVerify has all of those arguments like `-Ppact.provider.version` but those dont seem to work on ./gradlew pactPublish

bzifkin
2020-08-17 20:56
ive been able to get consumer versions to work by putting it in the pact publish closure though

bzifkin
2020-08-17 20:58
```pact { publish { providerVersion = getCommitSha() //tags = ['tags'] pactBrokerUrl = "http://localhost:9292" }``` but when i have tags in there like that i get this message `Link 'pb:pacticipant-version-tag' was not found in the response`

jarmy
2020-08-17 21:00
I?m able to do this with the following ``` publish { tags = [project.git.branchName] // https://docs.pact.io/getting_started/versioning_in_the_pact_broker // overrides the project.version def gitSha = "git rev-parse --short HEAD".execute().text.trim() version = gitSha }```

bzifkin
2020-08-17 21:01
yeah thats more or less what i have... and that works when you do `./gradlew pactPublish` ?


bzifkin
2020-08-17 21:02
interesting

bzifkin
2020-08-17 21:04
we must be using different versions because if i switch providerVersion to version it doesnt work for me....what version are you on in your consumer?

bzifkin
2020-08-17 21:04
```plugins { id 'au.com.dius.pact' version '4.1.6' apply false }``` ```apply plugin: 'au.com.dius.pact'```

bzifkin
2020-08-17 21:05
thats at my root build.gradle

phil.endsley
2020-08-17 21:08
Yeah, we do the same. ```pact { publish { pactDirectory = 'pact/dir' pactBrokerUrl = 'https://pactbroker/' tags = [project.gitBranch] providerVersion = "${project.version}-${gitRevision}" } }``` Using classpath 'au.com.dius.pact.provider:gradle:4.1.6'

jarmy
2020-08-17 21:08
`classpath "gradle.plugin.au.com.dius:pact-jvm-provider-gradle:4.0.10"`

bzifkin
2020-08-17 21:11
oh weird

bzifkin
2020-08-17 21:12
if i switch my pactBrokerUrl from the hosted one to the one at `localhost:9292` it works

phil.endsley
2020-08-17 21:12
Difference in version of hosted vs local pact broker maybe?

bzifkin
2020-08-17 21:12
must be hosting a different version

bzifkin
2020-08-17 21:12
yeah think so

matt.fellows
2020-08-17 21:15
Yes, you can add metadata to a message pact


matt.fellows
2020-08-17 21:16
When you say hosted do you mean Pactflow or your own?

bzifkin
2020-08-17 21:17
our own

matt.fellows
2020-08-17 21:17
You can check the hosted version by looking at the response headers

matt.fellows
2020-08-17 21:17
Ahh

matt.fellows
2020-08-17 21:17
There should be a git sha you can use to see how old it is

bzifkin
2020-08-17 21:18
gotcha thank you...ill talks to our devops people about updating the hosted instance

bzifkin
2020-08-17 21:19
okie doke well now that ive got that figured out that leads me to another question. Since it looks like `pactPublish` only takes in arguments from the closure rather than cli properties how would i set a tag on a deploy to an env name? Basically once a consumer has been verified we want to deploy it qa or test or prod

bzifkin
2020-08-17 21:22
the situation being this - a consumer branch is pushed, our build runs pactPublish and we take the branch name and commit sha from the closure. Then the build run continues and the contract is verfied, at that point the consumer is deployed to lets say `test` ....i wouldnt be able to use pactPublish to tag it here correct? The pact broker cli would be my only way correct?

jarmy
2020-08-17 21:24
The pact-broker cli would be able to handle this ``` stage('Prod: Tag pact contract with environment') { steps { sh "pact-broker create-version-tag --pacticipant=${PROVIDER} --broker-base-url=${BROKER_BASE_URL} --version=${gitReference} --tag=${PROD_ENV}" } }```

bzifkin
2020-08-17 21:25
awesome thank you, figured the cli was the way to go but wasnt sure if there was another way

uglyog
2020-08-17 22:31
What version of the pact broker are you using?

bzifkin
2020-08-18 17:18
i believe latest...this is my docker-compose for my local: ``` pact_broker: image: pactfoundation/pact-broker ports: - "9292:9292" depends_on: - postgres environment: PACT_BROKER_DATABASE_USERNAME: postgres PACT_BROKER_DATABASE_PASSWORD: password PACT_BROKER_DATABASE_HOST: postgres PACT_BROKER_DATABASE_NAME: postgres PACT_BROKER_PORT: "9292"``` Having trouble googling the right thing to confirm that docker-compose defaults to latest if image version isnt specified

os.shulyak
2020-08-19 11:34
Hey all. Is it possible to create pact contract without `"matchingRules"` using `MessagePactBuilder` for testing message queues?

brendan.donegan
2020-08-19 16:18
has joined #pact-jvm

brendan.donegan
2020-08-19 16:18
Hi. We are trying to add an interaction where there is an ID in the URL that needs to be replaced as the object which the requests acts on needs to be set up by the state handler. The consumer is using pact-js but the provider verification is using Junit and I cannot see any way to update the url. I have seen https://github.com/DiUS/pact-jvm/tree/master/provider/junit#returning-values-that-can-be-injected but it's a bit vague since it just mentions "There are methods on the consumer DSLs that can provider an expression that contains variables" but I can't find anything in the pact-js docs about this.

amer.mohammed
2020-08-20 08:58
Hi, I'm trying to verify the async pact in provider. The provider uses the Spring framework's AmqpTemplate's convertAndSend() method which looks like this: amqpTemplate is autowired ```@Override public void publish(String id, Product product) { amqpTemplate.convertAndSend(exchangeName, routingKey, product, new ProductMessagePostProcessor(id)); }``` How can I verify the message string prepared by this? Thanks.



matt.fellows
2020-08-20 09:14
Might be useful examples for you

amer.mohammed
2020-08-20 09:25
Hi Matt, thanks for your response. I've gone through the examples provided and I see that in ProductRepository we're preparing the Message object but in my case of using AmqpTemplate that's out of my hand. convertAndSend method is responsible for preparing the Message and sending it.

matt.fellows
2020-08-20 09:29
I can't give much more advice other than to say you need to be able to have control over how what the message looks like vs the specific protocol (in this case Kafka) that sends it

matt.fellows
2020-08-20 09:29
Because iact wants to see the message before sending (provider side) and after receiving on the provider side. It doesn't know about kafka

bzifkin
2020-08-20 13:20
@uglyog does the latest pactBroker allow you to use gradle arguments for the version?

uglyog
2020-08-20 21:48
No, the broker knows nothing about Gradle parameters

bzifkin
2020-08-20 22:51
gotcha, so then the way to set the version tag would just be through the gradle task correct

bzifkin
2020-08-20 22:51
it could also be done from the cli right?

uglyog
2020-08-20 23:02
Sorry, I still don't really understand why you are having an issue with this. The Gradle task allows you to configure the tag on the publish block. This is a code block, which means you can set it to anything. If you use a `-P` parameter, Gradle creates that as a property on the project. You can then assign that property to the tag list. Or, is you use `-D` Gradle will set it as a system property, and you can then use `System.getProperty` to assign the tag to the tag list. You might even be able to get the command line arguments as well, and then set the tag list from that.

bzifkin
2020-08-20 23:05
so my original issue was that i couldnt tag via the gradle closure: ```pact { publish { providerVersion = getCommitSha() //tags = ['tags'] pactBrokerUrl = "http://localhost:9292" }``` the `tags = ['tags']` portion would give me an error

bzifkin
2020-08-20 23:07
that turned out to be an issue w/ broker version. I was asking about doing it via the parameters on the `./gradlew pactPublish` command, but it didnt seemed like those worked....now that ive got it working in the closure though its a non-issue

uglyog
2020-08-20 23:09
`-PproviderVersion=value` will allow you to use `tags=[project.providerVersion]`

bzifkin
2020-08-20 23:14
ahhh so if i did something like `./gradlew pactPublish -PproviderVersion=value tags=[project.providerVersion]`that would allow me to tag my consumer?

uglyog
2020-08-20 23:24
No, `./gradlew pactPublish -PproviderVersion=value` and then in the publish block ```tags = [ project.providerVersion ]```

bzifkin
2020-08-21 00:58
gotcha, thanks @uglyog!

theuiser
2020-08-21 21:45
Curious if anyone else has run into lowered code coverage in Sonar when running provider pact verification tests. I was following the instructions on this page: https://github.com/DiUS/pact-jvm/tree/master/provider/junit5 Whenever we include the maven-surefire-plugin, our code coverage goes from 86% to 6%.

theuiser
2020-08-21 23:28
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> <configuration> <useSystemClassLoader>false</useSystemClassLoader> <systemPropertyVariables> <pact.broker.host>http://xx.xxx.xxx.xxx</pact.broker.host> <pact.provider.version>${version}</pact.provider.version> <pact.verifier.publishResults>true</pact.verifier.publishResults> </systemPropertyVariables> </configuration> <dependencies> <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-surefire-provider</artifactId> <version>1.2.0</version> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.2.0</version> </dependency> </dependencies>

theuiser
2020-08-21 23:30
See my config below: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> <configuration> <useSystemClassLoader>false</useSystemClassLoader> <systemPropertyVariables> <pact.broker.host>http://xx.xxx.xxx.xxx</pact.broker.host> <pact.provider.version>${version}</pact.provider.version> <pact.verifier.publishResults>true</pact.verifier.publishResults> </systemPropertyVariables> </configuration> <dependencies> <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-surefire-provider</artifactId> <version>1.2.0</version> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.2.0</version> </dependency> </dependencies>

ranjanayush03
2020-08-22 18:33
Hi All, I am using m/gradlew test --info to verify the results and publish it on to the broker but however while I am able to set provider.publish.results in the Gradle command to true but the provider.version property is not reflecting the correct version that I am setting on the command line..it is unable to pick the version (showing as 0.0) Like is there a way to do set the version on ./gradlew test

matt.fellows
2020-08-22 23:43
mm is it possible that the pact phase is overwriting the other unit tests? (just guessing, I don?t really know the Maven ecosystem all that well)

uglyog
2020-08-22 23:52
Could also be `useSystemClassLoader` is causing that. You might need to split you test run in two, normal unit tests with code coverage, and then the pact tests


ranjanayush03
2020-08-24 03:32
Thank you @uglyog

anddreiu
2020-08-24 09:10
Hi. I am trying to implement Pact tests for a case where the provider uses certificates. I've set the provider maven plugin to use the truststore, but the error that I get is: "sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target". I've used mvn pact:verify on the provider side. On the consumer side I did not set anything related to certificates. Do I need to do something on the consumer? Are there any examples on how to implement this kind of tests? Thank you.

amer.mohammed
2020-08-24 09:11
shouldn't pact intercept the final message sent from the publisher just like pact intercepts the REST requests and maches the stubs defined and proceed? I don't see any way I can grab the message string by using AmqpTemplate abstraction.

matt.fellows
2020-08-24 10:19
Any reason you have to use https?

matt.fellows
2020-08-24 10:20
Where possible avoid. Assuming you can't tho no nothing on the consumer side to do

anddreiu
2020-08-24 10:26
I've tried to use insecure=true in HttpTarget for the Provider test, but it looks like the request fails

dianaszaharia
2020-08-24 13:32
Hi all, I'm trying to use `pathFromProviderState`so my pact has a generator that looks something like ``` Generators(categories={PATH={=ProviderStateGenerator(expression=/operations/{id}, type=STRING)}})``` and my provider state method returns a map of "id" and its UUID value; but for some reason the path generator generates a null path, any known issue on this side? using pact-jvm 4.0.10

dianaszaharia
2020-08-24 14:35
never mind, I was missing the $ in expression `/${id}` :grin::woman-facepalming:

bzifkin
2020-08-24 16:34
@phil.endsley @uglyog sorry i keep asking variations of the same question: how to set consumer versions... when i run a PR build i want to set the version to commit sha and tag w/ branch name. I can do both of these easily by properties in the gradle closure

bzifkin
2020-08-24 16:37
however when a pr is merged i want to tag w/ `master` and set the version to the new version of the app. I know the tag through the `./pact-broker create-version-tag` cli command....and i know i could also do the same w/ setting the consumer version w/ the `./pact-broker publish` cli command

bzifkin
2020-08-24 16:38
problem w/ the publish command though is that you need to specify the individual pacts, which would be a pain for consumers w/ multiple providers.....is there another way to set the consumer version more dynamically?

bzifkin
2020-08-24 17:13
hey all - im having trouble understanding how to use tags w/ consumer feature branches. When I open a PR for a feature branch and tag it I want it to go to the broker and check for a provider w/ tag = `branch_name`. If the tag doesnt exist then it should fall back and verify against the master branch of the provider

bzifkin
2020-08-24 17:18
I know how to do this from the provider side - set consumerVersionSelectors w/ the tag `branch_name` and set the fallBack as `master`

bzifkin
2020-08-24 17:18
not sure how to do w/ consumer though....seems like webhooks would be the way to go?

bzifkin
2020-08-24 17:26
or is pending pacts the solution here?

phil.endsley
2020-08-24 17:34
Why do you need to do this from the consumer side? What are you checking broker for? I thought the only thing the consumer should do with broker is publishing the pact after it's generated

bzifkin
2020-08-24 17:41
hmmm....you know actually i think youre right i dont need it

bzifkin
2020-08-24 17:45
to confirm my understanding of how the flow should be: 1. consumer published contract tagged w/ `branch_name`and tests against master of provider. It fails, turning consumer build red, but b/c pending pacts, keeps provider green. `branch_name` is marked as pending 2. make a branch on provider and set the consumer version selector to `branch_name`. Push the provider branch and it will make a call to retrieve the consumer `branch_name` and publish the results. If it's green then `branch_name` will be marked as verified. 3. merge provider and consumer

bzifkin
2020-08-24 17:50
correct?

phil.endsley
2020-08-24 18:02
> consumer published contract tagged w/ `branch_name`and tests against master of provider. If you're using web hooks, yes > It fails, turning consumer build red, but b/c pending pacts, keeps provider green.  No. If providers fail, their builds will fail. Pending pacts will keep providers green if verification fails (assuming it is a pending pact) Consumers will only fail if their own tests (the ones used to generate the actual pact) are failing. If this happens, the contract won't be created/published. > `branch_name` is marked as pending I'm pretty sure the pending state is calculated by the broker itself. Pacts themselves aren't marked as pending, because it depends on which provider tag is running verification. A pact is pending if the provider tag has never had a successful verification against it. For example, it's possible for `branch_name` to NOT be pending for provider tag `feature-x` , but it IS pending for provider tag `main_branch` > make a branch on provider and set the consumer version selector to `branch_name`. Push the provider branch and it will make a call to retrieve the consumer `branch_name` and publish the results. If it's green then `branch_name` will be marked as verified. Yes > merge provider and consumer Yes

phil.endsley
2020-08-24 18:04
> It fails, turning consumer build red, but b/c pending pacts, keeps provider green. To elaborate a little further: The consumer build will be green, provider will also be green (with pending pacts). `can-i-deploy` will fail though, when trying to deploy the ocnsumer. This is the safety net that prevents bad deployments. The failed verification will also still be published to the broker. This is what tells the teams that there is an issue, and something needs to change (either consumer or provider)

bzifkin
2020-08-24 18:15
Thanks Phil. As far as the consumer build turning red i guess i was imagining that when the failed verification was published to the broker we would have it alert the CI jobs and turn the build red. Probably not that simple, will just use can-i-deploy w/ a retry. I'm confused by what you mean w/ > A pact is pending if the provider tag has never had a successful verification against it. For example, it's possible for `branch_name` to NOT be pending for provider tag `feature-x` , but it IS pending for provider tag `main_branch` if the consumer publishes the tagged branch and that tag does not yet exist on the provider side what happens?

phil.endsley
2020-08-24 18:25
> if the consumer publishes the tagged branch and that tag does not yet exist on the provider side what happens? You don't _have_ to name/tag branches the same between consumer/provider. When you run provider verifications, you have to specify the `providerTags` attribute when using pending pacts. If that provider tag does not have any successful verifications for the consumer pact, the pact is pending. If it has had at least one successful verification, it is not pending. So let's say we haver a consumer pact tagged `consumer-new-feature` . We have a provider tagged `main_branch` Since `main_branch` does not have any successful verifications, `consumer-new-feature` is pending for `main-branch`. If provider verifications fail, the build stays green, and a failed verification is published to broker If we have a provider tagged `provider-new-feature`, the same holds true. Let's say we then commit a change that makes the tests pass. A successful verification would then be published to broker between `consumer-new-feature` and `provider-new-feature`. Because it has now been verified, it is no longer pending. So, if you make another change to the provider, you will get a failed verification, and the build will turn red.

phil.endsley
2020-08-24 18:26
If the `providerTags` does not exist in broker, I am pretty confident it will not pick up the pending pact. It has to be explicitly included in the consumer version selectors

phil.endsley
2020-08-24 18:27
But, in the example above, even if `consumer-new-feature` and `provider-new-feature` have a successful verification, `consumer-new-feature` is still pending for `main-branch` , because `main-branch` has never published a successful verification for that pact

phil.endsley
2020-08-24 18:40
> however when a pr is merged i want to tag w/ `master` and set the version to the new version of the app Do you build master when you merge into it? If not, I would recommend doing that. If yes, branch name should just be reused when publishing, and be correct (`master`). So that part should just work. For the version, you might have to do some special gradle logic to determine what the property value should be in the closure

sudhachilamakuri
2020-08-24 20:02
has joined #pact-jvm

sudhachilamakuri
2020-08-24 20:03
Hi Guys, I need some help I am at the early stage of implementing Pact, I have scenario where I will get a code from the response of one request and I want to use that code in the request body of next request to get access token in the response , how can I write provider tests , did some one worked this kind of scenario, if yes can you provide some examples pls

sudhachilamakuri
2020-08-24 20:03
I am using Pact Junit5

phil.endsley
2020-08-24 20:28
At an abstract level, I think you would have two separate pacts for this. One for making a request and getting some response (i.e. the code). And another for a request that sends some data (i.e. the code). Ideally, you can leverage provider states to put the provider in such a state that it is expecting the code you're sending with the request. This would let you decouple the tests from expecting the same code between them. Is this by chance for authentication using OAuth? If so, give this a read: https://docs.pact.io/provider/handling_auth/

sudhachilamakuri
2020-08-24 21:36
@phil.endsley thanks for quick response

sudhachilamakuri
2020-08-24 21:36
~I will go through the document~

sudhachilamakuri
2020-08-24 21:44
yes they are two separate pacts, one is generating code and I want to use this code in the next request to get accessToken in the response

sudhachilamakuri
2020-08-24 21:52
if possible could you please share an example how to use provider states in this scenario

sudhachilamakuri
2020-08-24 21:52
thanks in advance

abubics
2020-08-24 23:56
One important fundamental here (not sure where it is in the docs): Pact tests are not for behaviour (i.e. they're stateless). They are specific, isolated, and deterministic. You don't want to share responses from one test in another, because then the tests are coupled and have to be run in order :slightly_smiling_face:

uglyog
2020-08-25 00:30
That error means the certificate is not trusted. Is the provider using a self-signed certificate?

matt.fellows
2020-08-25 02:23
Look for the Pact JVM workshop in the docs. It had an example of how to deal with auth

matt.fellows
2020-08-25 02:23
In Pact every single interaction is independent of the other. In fact, the order of execution should not be relied upon

matt.fellows
2020-08-25 02:24
Provider states is how we deal with this

heytaco
2020-08-25 03:57
has joined #pact-jvm

heytaco
2020-08-25 03:57
Hi there! My name is HeyTaco!, and you can use me to give people tacos to show your appreciation. My tacos will spread joy through Slack!

anddreiu
2020-08-25 06:06
yes

anddreiu
2020-08-25 06:08
I am using the same certificate to make a call using SoapUI and it works, so I am doing something wrong in the Pact tests

uglyog
2020-08-25 06:15
How are you running the verification?

anddreiu
2020-08-25 06:15
mvn pact:verify

anddreiu
2020-08-25 06:16
and I tried also with Junit runner

uglyog
2020-08-25 06:52
`mvn pact:verify` is for verifying a pact file against a running server.

uglyog
2020-08-25 06:53
If you use a unit test, you don't use that command.

uglyog
2020-08-25 06:53
The tests will run as part of `mvn verify`

anddreiu
2020-08-25 06:55
yes, I was trying to verify a pact file against the provider


anddreiu
2020-08-25 06:57
yes, that's what I tried

uglyog
2020-08-25 06:57
And you still got that error?

anddreiu
2020-08-25 06:59
now I get `Request Failed - null`

anddreiu
2020-08-25 06:59
`1.1) org.apache.http.client.ClientProtocolException`


robert.strehli
2020-08-25 07:53
has joined #pact-jvm

anddreiu
2020-08-25 07:58
```Caused by: org.apache.http.ProtocolException: The server failed to respond with a valid HTTP response```

uglyog
2020-08-25 08:02
Probably need to enable debug logging to see what is going on. `-X` parameter should do that

sudhachilamakuri
2020-08-25 09:05
`thanks for the response every one

dianaszaharia
2020-08-25 09:42
hey, is `valueFromProviderState` available when building json bodies with LambdaDSL?


anddreiu
2020-08-25 11:09
yeah, I tried that. still not found the problem even if I enabled debug logging. when I use http (like below), I get `Caused by: org.apache.http.ProtocolException: The server failed to respond with a valid HTTP response` ```<protocol>http</protocol> <insecure>true</insecure>``` when I use https, I get `http://javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target` ```<protocol>https</protocol> <insecure>false</insecure>```


anddreiu
2020-08-25 12:20
I think the problem is the fact that I am using the keystore and not the truststore. when using the SoapUI I set the keystore and then I am able to submit the request. But in Pact I think that I need to set the truststore... it's a bit of a mess in my head...

dee_n
2020-08-25 14:58
has joined #pact-jvm

dee_n
2020-08-25 15:13
Hello, I have two Pact Consumer test classes (see this : https://github.com/DiUS/pact-jvm/issues/1194) which should run during the integration tests. But one of them always fail. How can I tear down the server after the test ran ?

phil.endsley
2020-08-25 15:56
This isn't really a Pact question. It's more of a Spring Boot question. Spring should do this automatically. I suspect the tests are being ran in parallel. You should be able to fix this by telling your Spring Boot test to use a random (unused) port when it spins up the application context. Spring Boot Docs: https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-testing-spring-boot-applications (Look for RANDOM_PORT) Spring Boot Code Example: https://spring.io/guides/gs/testing-web/

phil.endsley
2020-08-25 16:39
Can you use `getPactDslObject().valueFromProviderState` ?

dee_n
2020-08-25 16:57
Thanks @phil.endsley ! Sorry for asking this question here. The strange thing is that both Pact tests works fine when performing "*mvn install*" in IntelliJ but not when executing it in standalone Maven/Jenkins.

dianaszaharia
2020-08-25 17:57
Yep, I got around it by casting it to PactDslJsonBody and then applying valueFromProviderState. `getPactDslObject()` works better, was not aware of it. Thanks! :taco:

uglyog
2020-08-25 22:53
```<protocol>https</protocol> <insecure>true</insecure>``` :point_up: protocol must https when using insecure

sathisan
2020-08-26 04:30
has joined #pact-jvm

sathisan
2020-08-26 04:57
Hi All Is there a Way to check for type e.g Stringtype if my contenttype is text/plain.... So far i Think the stringtype, integertype etc. can only be checked when used in combination with PactDslJsonbody or PactDslJsonArray?

matt.fellows
2020-08-26 05:03
I don?t think it has matching on text/plain but I might be wrong. Is the response JSON encoded as text/plain?

matt.fellows
2020-08-26 05:03
What are you trynig to match - just strings in general? Regex matcher might be a thing

sathisan
2020-08-26 05:38
Yes the response is encoded as text/plain..at the Moment I can only check for concrete values which I want to avoid Yes Strings and other Custom types which I defined in classes

matt.fellows
2020-08-26 06:39
ok, sorry I?m not sure about the JVM dsl and if it can do that. but for the benefit of others, it would be ideal to understand what the req/responses should look like to help you

uglyog
2020-08-26 06:41
I think the issue is that PactDslJsonbody or PactDslJsonArray are meant to be used with JSON bodies. They don't work with plain text

matt.fellows
2020-08-26 06:42
yes, sorry I thought that was clear from an earlier response

anddreiu
2020-08-26 06:51
`Request Failed - Received fatal alert: bad_certificate`


uglyog
2020-08-26 06:58
> You need to add the root cert to the keystore as well.

anddreiu
2020-08-26 07:00
thanks. my question is: do I need to use the keystore or the truststore? because the property is <trustStore>, but I thought that I should use the keystore because I am the client

uglyog
2020-08-26 07:02
The keystore should have your private key for the cert, while the truststore needs to have the root cert in it

uglyog
2020-08-26 07:03
You can either supply a truststore to use, or put the root cert in the JVM default one

uglyog
2020-08-26 07:04
But the `insecure` option should bypass all that

anddreiu
2020-08-26 07:04
yes, but it looks like with insecure=true it doesn't work

uglyog
2020-08-26 07:05
Sorry, keystore just needs the public key, not the private

anddreiu
2020-08-26 08:23
@uglyog - is it possible to set the truststore for the provider and to specify the keystore for the client?

anddreiu
2020-08-26 08:25
I am thinking that using this we are setting the truststore on the provider side: ```<plugin> <groupId>au.com.dius.pact.provider</groupId> <artifactId>maven</artifactId> <version>4.1.0</version> <configuration> <serviceProviders> <serviceProvider> <name>provider1</name> <pactFileDirectory>path/to/pacts</pactFileDirectory> <trustStore>relative/path/to/trustStore.jks</trustStore> <trustStorePassword>changeit</trustStorePassword> </serviceProvider> </serviceProviders> </configuration> </plugin>``` But wouldn't be needed also the keystore to be set somewhere for making the request?

anddreiu
2020-08-26 09:20
I was trying now to set the keystore using maven parameters, but still no luck ```-Djavax.net.ssl.keyStore= -Djavax.net.ssl.keyStorePassword=```

amer.mohammed
2020-08-26 09:54
Hi, For async communication, we're using rabbitMq. The type of payload is a domain object. How can we define a pact for that? And how can we verify it? The examples I've found are implemented for stringified json.

amer.mohammed
2020-08-26 09:56
Payload and it's properties looks like this in rabbitMQ headers: __TypeId__: com.domain.basket.Product e2eData: 1234123412341243124321413421341 content_encoding: UTF-8 content_type: application/json payload: {"id":"242342", ...}

sathisan
2020-08-26 12:31
Hi guys I have one question regarding the provider Test If i verify the contract on the provider Side, what is the difference between verifying against the MockMVC Target and the target which is specified as HttpTarget?

francislainy.campos
2020-08-26 14:08
Hi, is there anything that one can do to beautify the logs a bit so they are a bit easier to read?

uglyog
2020-08-26 23:13
Could you raise an issue for this at the github project? The `insecure` parameter is meant to not require any of this and work with self-signed certs.

uglyog
2020-08-26 23:14
Until this is fixed, is there an option to not use HTTPS?

anddreiu
2020-08-27 06:44
no, can't using it without HTTPS

anddreiu
2020-08-27 06:45
> Could you raise an issue for this at the github project? The `insecure` parameter is meant to not require any of this and work with self-signed certs. I think it won't work with self-signed certs. I need to find a way to send that client certificate to the server, otherwise it won't be accepted

uglyog
2020-08-27 06:47
Does it require MASSL?

anddreiu
2020-08-27 06:49
not sure, it's something new also for me and I am trying to find out more

uladzislau_danilchyk
2020-08-27 09:57
Hi everyone! I'm trying to publish pacts to Pact Broker (https) which do not have authentication. How to deal with it? I received error for the PUT request when pacts are publishing: ```ERROR] [au.com.dius.pact.core.pactbroker.HalClient] PUT JSON request failed with status HTTP/1.1 301 Moved Permanently```

matt.fellows
2020-08-27 10:20
Can you please share the verbose http logs ? 301 is interesting, is there a proxy or something in front of it?

francislainy.campos
2020-08-27 11:43
Hi, I have a post request that takes date as a param. ```return builder .uponReceiving("A request to create a Zoom meeting") .path(createMeeting) .method("POST") .headers(headers) .body("{\"title\":\"My title\",\"start_time\":\"2020-08-28T14:30:00Z+01:00\",\"duration\":30,\"provider\":\"ZOOM\"}") .willRespondWith() .body(body) .toPact();``` But I'd like this to be dynamic, having perhaps today's or tomorrow's date, otherwise it would have an expired date. Could you please advise on how to do do this and if possible to keep it from the consumer side. Many thanks.


phil.endsley
2020-08-27 12:46
There was actually a blog written about this exact thing. I think this is what you're looking for. Though it uses the dsl, and it looks like you're defining the body as a raw json string https://pactflow.io/blog/dealing-with-relative-dates-in-contract-tests/

phil.endsley
2020-08-27 12:47
> You can now use the `dateExpression` function to have an expression be evaluated at runtime when the provider is verified. So our snippet becomes:

uladzislau_danilchyk
2020-08-27 13:20
I attached logs with DEBUG level.

uladzislau_danilchyk
2020-08-27 13:25
@matt.fellows, pay attention that first call is going to HTTPS. but after that call is going to HTTP on 26 line.

uladzislau_danilchyk
2020-08-27 13:33
@matt.fellows. we are just deployed pact broker into Kubernetes where balancer is on front of top of it. No proxy.

francislainy.campos
2020-08-27 15:08
Thank you. I can try that. I actually use the body as raw string as when try to use it with dsl for some reason it won't work for me.

francislainy.campos
2020-08-27 15:08
```@ExtendWith(PactConsumerTestExt.class) public class PACTConsumerEdUiVcTest { Map<String, String> headers = new HashMap<>(); String createMeeting = "/manage/create-meeting"; @Pact(provider = VC, consumer = ED_UI) public RequestResponsePact createPact(PactDslWithProvider builder) { headers.put("Content-Type", "application/json"); DslPart body = new PactDslJsonBody() .stringValue("start_time", "2020-08-28T14:30:00Z+01:00"); return builder .uponReceiving("A request to create a Zoom meeting") .path(createMeeting) .method("POST") .headers(headers) .body(new PactDslJsonBody() .stringValue("title", "My title") .stringValue("start_time", "2020-08-28T14:30:00Z+01:00") .stringValue("provider", "ZOOM") .numberValue("duration", 30)) // .body("{\"title\":\"My title\",\"start_time\":\"2020-08-28T14:30:00Z+01:00\",\"duration\":30,\"provider\":\"ZOOM\"}") .willRespondWith() .body(body) .toPact(); } @Test @PactTestFor(providerName = VC, port = "8080") public void runTest() { //Mock url RestAssured.baseURI = "http://localhost:8080"; Response response = RestAssured //todo: dynamic start time that won't expire. 27/08/2020 .given() .headers(headers) .when() .body(new PactDslJsonBody() .stringValue("title", "My title") .stringValue("start_time", "2020-08-28T14:30:00Z+01:00") .stringValue("provider", "ZOOM") .numberValue("duration", 30)) // .body("{\"title\":\"My title\",\"start_time\":\"2020-08-28T14:30:00Z+01:00\",\"duration\":30,\"provider\":\"ZOOM\"}") .post(createMeeting); assert (response.getStatusCode() == 200); } }```

francislainy.campos
2020-08-27 15:11
Would you be able to tell me what I'm missing on this part @phil.endsley and then I'd try the dynamic date as per the blog post you shared? Thank you very much again.

phil.endsley
2020-08-27 15:23
I'm not very familiar with RestAssured. Only used it a couple times when playing around with it. I'm guessing it's because you're using `PactDslJsonBody` in the RestAssured `.body` method. Maybe try the raw json there like you had before, but keep using the `PactDslJsonBody` in the pact builder.

phil.endsley
2020-08-27 15:23
Maybe start by proving it out with a hard coded date/time, and then make it work dynamically?

francislainy.campos
2020-08-27 15:30
Yeah, you're right. Keeping RestAssured as it was fixed the issue to create the contract with DSL. Will get back to the blog post and see about the dynamic date.

francislainy.campos
2020-08-27 15:31
This is actually another and related question I've been having for some time: Why do we need to send a body post twice, under the builder and within the runTest piece?

phil.endsley
2020-08-27 15:33
The builder is defining the expected contract, it's not sending the request, rather defining what it should look like. The runTest (the second body) is you building a real request to send

francislainy.campos
2020-08-27 15:35
Cool, so then only the RestAssured part actually interacts with the call and I'd probably then add the dynamic date only to it if I'm understanding it properly.

francislainy.campos
2020-08-27 15:35
I'll try and work on it and see what happens.

phil.endsley
2020-08-27 15:40
The pact builder will definitely need a change. Not sure about the rest assured part. Essentially, the pact builder will change to allow more flexibility for the consumer's request, vs expecting exactly `"2020-08-28T14:30:00Z+01:00"`

francislainy.campos
2020-08-27 15:43
You mean the difference between stringValue and stringType? This is amended now. ```headers.put("Content-Type", "application/json"); DslPart body = new PactDslJsonBody() .stringType("topic", "My title") .stringType("id", "94668716626") .stringType("join_url", "https://zoom.us/j/94668716626?pwd=S3pldTFmdjcwYnZRZS80UzBidlBMQT09") .numberType("duration", 30) .stringType("password", "Hello"); return builder .uponReceiving("A request to create a Zoom meeting") .path(createMeeting) .method("POST") .headers(headers) .body(new PactDslJsonBody() .stringType("title", "My title") .stringType("start_time", "2020-08-28T14:30:00Z+01:00") .stringType("provider", "ZOOM") .numberType("duration", 30)) .willRespondWith() .body(body) .toPact();```

phil.endsley
2020-08-27 15:45
Also, to offer some unsolicited feedback, based on your code above, it looks like you're using RestAssured for your consumer tests. This doesn't follow best practices, because it allows your actual code base to drift from your contract. Instead, you should be calling the method from your code base that would actually make the web call. This couples your code base to the contract, since it makes sure your code is actually doing what you're contract is doing.

phil.endsley
2020-08-27 15:46
If you change the implementation of what your consumer is, your test will still pass, because it's not calling the actual method that invokes the web call

francislainy.campos
2020-08-27 15:49
I get you. I'd need to learn how to do this way you're suggesting, as I'm not the person who does the development but the automation engineer instead. But can try and figure it out.

sathisan
2020-08-27 16:33
Hi everyone As far as I understood, with mockmvc the contract is verified against the weblayer( controller) and with Httptarget the contract is verified against the whole Server with Application context. But in the official documentation, it is stated that pact is testing messages between two Applications at HTTP Level. So if I am testing at Http Level, does it have an impact for my testing if service Layer is mocked or not mocked?

francislainy.campos
2020-08-27 17:49
``` @Test @PactTestFor(providerName = VC, port = "8080") public void runTest() { //Mock url RestAssured.baseURI = "http://localhost:8080"; Map<String, Object> map = new HashMap<>(); map.put("title", "MyTitle"); map.put("start_time", new Date().toString()); map.put("duration", 30); map.put("provider", "ZOOM"); Response response = RestAssured //todo: dynamic start time that won't expire. 27/08/2020 .given() .headers(headers) .when() .body(map) .post(createMeeting); assert (response.getStatusCode() == 200); }```

francislainy.campos
2020-08-27 17:50
Still with RestAssured but I was able to pass a dynamic date like this.

phil.endsley
2020-08-27 17:50
:tada:

francislainy.campos
2020-08-27 17:51
:slightly_smiling_face:

francislainy.campos
2020-08-27 17:52
For your suggestion I'll try to learn that, but I think for this specific scenario may not be able to implement it as I'm actually doing the consumer tests from outside the consumer codebase, which means I would not have access to the method that does the web call.

matt.fellows
2020-08-27 23:44
I?m going to guess that your load balancer or some configuration is redirecting it to http


matt.fellows
2020-08-27 23:46
Yousaf also wrote an interesting post that might be helpful: https://medium.com/@you54f/securing-the-pact-broker-with-nginx-letsencrypt-624a890be9a8

matt.fellows
2020-08-27 23:47
See also https://github.com/DiUS/pact_broker-docker/issues/58. It?s possible that the response body shows http links in the response, because of a misconfiguration at the LB. If the application doesn?t know it?s on http, it can?t write the relations into the body of the hypermedia response, which defaults to http

matt.fellows
2020-08-27 23:48
all of those would point to incorrect configuration -> *TL;DR if your LB terminates SSL and sends traffic to the pact broker on port 80 and doesn?t set appropriate headers, you?ll get this issue*

abubics
2020-08-28 01:55
Yeah, that's not ideal. If your tests aren't exercising the actual code, they don't provide much value :thinking_face:

francislainy.campos
2020-08-28 06:10
Hi, they are exercising the actual code but not coded directed from the same consumer code base. They use RestAssured to do the api call and check the response against the contract.

francislainy.campos
2020-08-28 06:12
We have the specs on what the consumer needs and write both the consumer contract and verification from the same provider codebase.

phil.endsley
2020-08-28 12:50
Oh, maybe I misinterpreted/assumed the wrong thing. Do you have your consumer application running at port 8080? I thought you were using RestAssured to call the mock server directly

francislainy.campos
2020-08-28 17:11
We do the mocking when generating the contract by running it against the port 8080 but do the real testing against our services when verifying it from the provider side.

francislainy.campos
2020-08-28 17:13
As there's no resources available to write PACT from the UI team, we do both the consumer and verification from the provider codebase based on the specs they send us saying what the answer should look like, which they usually write on Confluence or similar page.

phil.endsley
2020-08-28 17:24
> We do the mocking when generating the contract by running it against the port 8080 Ok, so I think I assumed right then. The consumer pacts are tested against the mockserver (port 8080 is not a real instance of the consumer, right?). If that's the case, your consumer tests are not exercising the actual consumer code. It's essentially doing: ```ServiceA serviceA = mock(ServiceA.class); when(serviceA.doThing()).thenReturn("Success"); assert(serviceA.doThing().equals("Success");``` So if `doThing()` ever changes, the test will keep passing, and the contract will keep being published. This is the "drift" I was talking about before. It sounds like your provider is testing the actual code base, which is great. But, it's still not safe, because you're validating the provider response against a "hand written" contract. For the example above, you would ideally test it against a real version of `ServiceA`. This would ensure that the real behavior of `ServiceA` matches your defined contract. What you're doing bypasses some key features that (in my opinion) are what makes Pact better than other tools. It could also lead to the possibility of breaking changes being deployed without any tests failing. Ultimately, the tests are probably better than nothing. And it's up to you to weigh the risks/benefits you're getting out of it. If nothing else, now you're aware of the gap this leaves.

francislainy.campos
2020-08-28 17:28
Yes, exactly. We don't manage the consumer code base from our side and this opens the possibility of us being verifying fields that are part of this hand written contract by only believing they are all being used by the UI, which may not be always true if things changes and these specs are not updated accordingly.

francislainy.campos
2020-08-28 17:31
Thank you for the detailed feedback by the way. I always appreciate coming to this channel and talking to you guys as feel I learn something new and insightful every time.

phil.endsley
2020-08-28 17:55
If I'm not mistaken, you can still use mockmvc with the whole application context stood up. Either one should be fine for verification, since mockmvc is still making calls to your endpoint via http. Whether you mock the service layer or not is up to you to weigh the cost/benefits of doing so. I think there have been a couple threads in slack talking about where/when to mock, not sure if they're gone now though. The more you mock at higher levels (ex: service layer vs data layer) the more you're relying on that mocking being correct when verifying the contract. The more real instances you have, the more accurate your verifications will be. There's also warnings in the docs that make sure to distinguish between contract vs functional tests. https://docs.pact.io/consumer/contract_tests_not_functional_tests/

abubics
2020-08-31 01:37
Glad it's helpful, and thanks for your thorough explanations, @phil.endsley :confetti_ball: The best outcome would be if you can convince the consumer dev team to get contract tests into the actual codebase?that's really how it's intended to be used, and will deliver the best value :thumbsup: If nothing else, this thread could help convince them that the gap is very significant.

abubics
2020-08-31 01:39
I'm interested in this problem: > there's no resources available to write PACT from the UI team Is it just that they aren't currently devoting effort to writing these kinds of tests, or that their architecture makes it difficult to write these kinds of tests?

komeershettyvinod
2020-08-31 13:46
Hi I want to make a post request call to get the bearer token(used in authorization header) ,Since every time I run the provider tests, bearer token changes

komeershettyvinod
2020-08-31 13:46
I am using gradle for this

komeershettyvinod
2020-08-31 13:46
I went through the http://read.me

komeershettyvinod
2020-08-31 13:47
I am not sure how to use requestFilter object for post call and generate ouath key(in my case bearer)

komeershettyvinod
2020-08-31 13:47
dynamically and send for pact while run

komeershettyvinod
2020-08-31 13:48
any help please/

uglyog
2020-08-31 22:53
The request filter is just a callback that is invoked before the request is made. You can put whatever code you need in there, including making a HTTP request to get a token. But I would recommend fetching the token once before the test, and then just reusing it in the request filter.

komeershettyvinod
2020-09-01 06:16
ok thanks

komeershettyvinod
2020-09-01 06:19
Hi Team

komeershettyvinod
2020-09-01 06:20
I have a Get call for a contract to be made say the url is "http://dummyurl.com/id"

komeershettyvinod
2020-09-01 06:20
Here the id is dynamic

komeershettyvinod
2020-09-01 06:21
I want id to be ignored as part of verification both at consumer and provider side

uglyog
2020-09-01 06:21
You can use regular expressions for the paths

komeershettyvinod
2020-09-01 06:32
I do not see proper examples for regex for paths

komeershettyvinod
2020-09-01 06:32
Is it possible to share some examples?


komeershettyvinod
2020-09-01 06:42
ok thank you so much

francislainy.campos
2020-09-01 11:00
```@BeforeEach void before(PactVerificationContext context) { context.setTarget(new HttpsTestTarget(BASE_PACT_VC_URL, 443, "/")); getAuthorizationToken(UserType.TEACHER); }``` .. ```public static String getAuthorizationToken(UserType userType) { SUS_LOGIN = SUS_LOGIN_INT; String username = "QATeacher2_92025082_int"; String password = "E!1jmka1p62h"; String tenantPid = "92025081"; Map<String, Object> map = new HashMap<>(); map.put("username", username); map.put("password", password); map.put("tenantPid", tenantPid); Requests request = new Requests(); RequestSpecification rq = request.getRequestSpecification(""); Response r = rq.body(map).post(SUS_LOGIN); AUTHORIZATION_TOKEN = r.getBody().jsonPath().get("sifToken"); return AUTHORIZATION_TOKEN; }``` .. ```public class Requests { public RequestSpecification getRequestSpecification(String authorizationToken) { RequestSpecification rq = given() .contentType(OAuth.ContentType.JSON) .contentType("application/json\r\n") .header("Accept", "application/json").and() .header("Content-Type", "application/json") .header("Authorization", authorizationToken) .when() .log() .everything(); return rq; } }``` We're using Maven and RestAssured but this is how we do this if it can help you somehow.

komeershettyvinod
2020-09-01 11:40
Yeah, Thank you so much, But I am using Gradle as a provider

francislainy.campos
2020-09-01 14:07
Hi, maybe more of a Java question than PACT but I was looking for a sample where I'd validate whether the string returned is a valid email address if anyone has any please? Thanks a lot in advance.

phillip.lo
2020-09-01 16:34
has joined #pact-jvm

lzyzy1996
2020-09-01 17:09
has joined #pact-jvm

abagraw3
2020-09-01 21:45
has joined #pact-jvm

abagraw3
2020-09-01 21:45
Hi All! I'm trying to write a provider test using junit. I've contract files and I want to run them on multiple environment and hence a particular field in request body needs to be modified which is env specific. Is there any way to modify the value of an attribute in request body?

uglyog
2020-09-01 22:49
You'll need to use a regular expression. You can probably find one with a quick search with Google.

uglyog
2020-09-01 22:52
Pact has been designed to test the structure of requests. Unless the structure changes between environments (which would be pretty silly thing to do), you should not test the actual value but that the value is the correct type.

abubics
2020-09-02 00:10
At the same time, I'd advise against trying to definitively validate email addresses (with a regex or otherwise) . . . the spec is notoriously free, and many assumptions about how email addresses should be structured are wrong. For example, more TLDs may exist in the future, and many special characters are valid before the `@` . . . practically, with a regex, the most useful thing you can validate is that there are characters before and after the `@`, and that's it.

abubics
2020-09-02 00:10
(also, it's kinda not the point of a pact test, that's more a unit testing thing)


matt.fellows
2020-09-02 00:14
what Ron said

francislainy.campos
2020-09-02 00:55
Cool, thank you both. :+1:

ashley.graf101
2020-09-02 01:49
has joined #pact-jvm

abagraw3
2020-09-02 04:09
```{ "provider": { "name": "stationlogin" }, "consumer": { "name": "desktoplogin" }, "interactions": [ { "description": "station login post request", "request": { "method": "POST", "path": "/ra/v1/login", "headers": { "Content-Type": "application/json" }, "body": { "teamName": "string", "channelCount": { "social": 100, "telephony": 100, "chat": 100, "email": 100 }, "chatCount": "string", "voiceCount": "string", "teamId": "string", "siteId": "string", "dn": "string", "usesOtherDN": true, "skillProfileId": "AXLxBfMapN8jdS1B8654", "emailCount": "string", "auxCodeId": "string" }, "matchingRules": { "body": { "$.dn": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.siteId": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.teamId": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.teamName": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.chatCount": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.emailCount": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.voiceCount": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.usesOtherDN": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.auxCodeId": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.skillProfileId": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.channelCount.telephony": { "matchers": [ { "match": "number" } ], "combine": "AND" }, "$.channelCount.email": { "matchers": [ { "match": "number" } ], "combine": "AND" }, "$.channelCount.chat": { "matchers": [ { "match": "number" } ], "combine": "AND" }, "$.channelCount.social": { "matchers": [ { "match": "number" } ], "combine": "AND" } } } }, "response": { "status": 202 } } ], "metadata": { "pactSpecification": { "version": "3.0.0" }, "pact-jvm": { "version": "3.5.23" } } }```

abagraw3
2020-09-02 05:16
``` import au.com.dius.pact.provider.junit.Consumer; import au.com.dius.pact.provider.junit.PactRunner; import au.com.dius.pact.provider.junit.Provider; import au.com.dius.pact.provider.junit.TargetRequestFilter; import au.com.dius.pact.provider.junit.loader.PactFolder; import au.com.dius.pact.provider.junit.target.HttpTarget; import au.com.dius.pact.provider.junit.target.Target; import au.com.dius.pact.provider.junit.target.TestTarget; import com.cdc.ccc.ra.functest.PactHelper; import org.apache.http.HttpRequest; import org.junit.Before; import org.junit.runner.RunWith; @RunWith(PactRunner.class) @Provider("stationlogin") @Consumer("desktoplogin") @PactFolder("pacts") public class AgentNewStationLoginPact { @TestTarget public final Target target = new HttpTarget("https", "http://ra.intgus1.myService.com", 443); private HttpRequest request; @Before public void before() { System.out.println("run before tasks..."); } @TargetRequestFilter public void requestFilter(HttpRequest request) { request.addHeader("Authorization", PactHelper.userAccessToken()); } }```

abagraw3
2020-09-02 05:48
I had generators in the contract file but I removed it since it generated random data and the test was failing.

robert.strauch_slack
2020-09-03 09:52
I'd like to implement a Pact consumer test in our Java EE application. This test shall invoke a consumer service method which would trigger the actual REST call. Here's the Pact test so far: ```java @ExtendWith(PactConsumerTestExt.class) @PactTestFor(providerName = "my-service") public class MyServiceConsumerTest { @Inject private MyService myService; @Pact(consumer = "myConsumer") public RequestResponsePact mail(PactDslWithProvider builder) { Map<String, String> headers = new HashMap<>(); headers.put("Content-Type", ContentType.getJSON().asString()); PactDslJsonBody jsonBody = new PactDslJsonBody() .stringValue("emailAddress", "") .stringValue("subject", "Test subject") .stringValue("content", "Test content") .asBody(); return builder .given("DEFAULT_STATE") .uponReceiving("request for sending a mail") .path("/mail") .method("POST") .headers(headers) .body(jsonBody) .willRespondWith() .status(Response.Status.OK.getStatusCode()) .toPact(); } @Test @PactTestFor(pactMethod = "mail") public void sendMail() { MailNotification mailNotification = MailNotification.builder() .emailAddress("") .subject("Test subject") .content("Test content") .build(); myService.sendNotification(mailNotification); } }``` The interesting part is this line: `myService.sendNotification(mailNotification);` As I'm running a consumer unit test, the injection of `MyService` does not work, i.e. results in `myService` being `null`. Moreover I think it would be necessary to tell the service to send its request against the Pact mock server? Of course I could just fire the final REST request in the test but that would ignore the service logic. I guess I'm missing something here?

matt.fellows
2020-09-03 10:42
> As I?m running a consumer unit test, the injection of `MyService` does not work, i.e. results in `myService` being `null`. Moreover I think it would be necessary to tell the service to send its request against the Pact mock server? Yes you?re spot on - both of those things are correct

matt.fellows
2020-09-03 10:42
> Of course I could just fire the final REST request in the test but that would ignore the service logic. and yes, do not do this! this test will forever pass if you ever change the details of `MyService`

matt.fellows
2020-09-03 10:43
I?m not familiar with the details of `Inject`, but I guess the test context is not aware of the annotation. I?m sure there are other ways to get that dependency injected, but if not, can you just create and instantiate it directly?

robert.strauch_slack
2020-09-03 11:05
That's what I was also thinking of. The problem is that this service has several other dependencies which I would need to mock/inject somehow. As you mentioned I'll probably need to check the injection mechanism...

matt.fellows
2020-09-03 11:09
Sorry I can?t help much more - when I last wrote Java the JSR 330 proposal (I think) was just becoming a thing

matt.fellows
2020-09-03 11:09
I can do it in spring, but only because I recently did a demo using that

robert.strauch_slack
2020-09-03 11:10
Yeah, Spring is so musch easier on this.

abagraw3
2020-09-03 13:45
Am I missing something here?

uglyog
2020-09-03 23:00
Generators will generate random values. If you're matchers are correctly configured, random values should not fail your test

uglyog
2020-09-03 23:02
You're using an old version of Pact-JVM. You should upgrade to a newer version.

abagraw3
2020-09-04 05:25
Thank you @uglyog & @matt.fellows for the inputs. I'm using pact-jvm-provider-junit v4.0.10.

uglyog
2020-09-05 03:21
That sounds like it might be a defect. Please raise an issue for it.

maciej.olko
2020-09-05 13:46
@lucaseverain :point_up:

lucaseverain
2020-09-05 13:46
has joined #pact-jvm

ashish_garg5
2020-09-08 10:50
Hi All, Just want to know whether pact version 4.0.x works with Spring boot 2.2 ? Thanks.

joao
2020-09-08 15:45
It should work, you just need to setup your MockMVCs object properly. What error have you encounter?

dabs1234
2020-09-09 07:59
has joined #pact-jvm

dabs1234
2020-09-09 07:59
Hello All, I am new to PACT and just did a POC with JUnit5 on simple microservice consumer and provider. Now I need to implement it on real springboot microservice which uses oauth2. What is the best way of achieving this? Any sample code would be a great help.

ashish_garg5
2020-09-09 11:15
no errors i did the POC using 4.0.x with Spring boot 1.x so just wanted to ask if there is any compatibility chart for pact version so that we make sure we are using the right version of pact. Thanks :slightly_smiling_face:

matt.fellows
2020-09-09 12:09
howtolearn

2020-09-09 12:09
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

matt.fellows
2020-09-09 12:10
in case you missed it in general, good JVM workshop with auth there

copalco
2020-09-10 12:55
has joined #pact-jvm

vit.barabash
2020-09-14 15:50
Hi all! I?m trying to implement provider test (spring+junit5) for the controller which uses reactive webClient. I?ve noticed that WebFlux controllers are supported since 4.1.7, but I can?t find any guide/example how to deal with it. Digging into WebFluxTarget implementation within the pact-jvm repo didn?t help yet. I was expecting something similar to the one with MockMvc with a replacement of the MockMvcTestTarget to WebFluxTarget, but it doesn?t seem to work :slightly_smiling_face: Can someone help with it or point me to the proper place in the documentation? Thanks in advance!

komeershettyvinod
2020-09-15 13:34
Hi

komeershettyvinod
2020-09-15 13:35
I am unable to follow the pact broker work flow, can any one help me what does Unverified means here and how to make it verified

komeershettyvinod
2020-09-15 13:37
I followed below steps 1. Consumer side - Generated a contract file (say consumer_pact.json) 2. At Producer side - Using above contract file, ran the publisher side tests(It passed) 3. Uploaded the common contract file generated in step 1 to pact broker using 'pactPublish' task

komeershettyvinod
2020-09-15 13:37
My question is how to verify the producer side tests

matt.fellows
2020-09-15 13:40
Steps should be: 1. Generate contract 2. Publish contract to pact broker 3. Verify the provider by configuring it to download from the broker 4. ?ensuring verification results are set to publish

matt.fellows
2020-09-15 13:40
if you don?t enable verification results, it won?t send the results back to the broker


matt.fellows
2020-09-15 13:41
howtolearn

2020-09-15 13:41
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

matt.fellows
2020-09-15 13:42
:point_up: useful pact jvm workshop there if you haven?t run

komeershettyvinod
2020-09-15 13:42
ok thanks Matt, one question from your steps , ideally the step 2 should always be from consumer side right?

matt.fellows
2020-09-15 14:11
Yes! The provider can't publish a contract on behalf of a consumer

matt.fellows
2020-09-15 14:11
(or rather it shouldn't, that would be like marking your own exam :joy:)

komeershettyvinod
2020-09-15 14:24
@matt.fellows Thank you, this helps

giuseppe.salvatore
2020-09-15 15:21
Hello everyone

giuseppe.salvatore
2020-09-15 15:22
has anybody ever done contract testing with apigee as a proxy between providers and consumers?

komeershettyvinod
2020-09-15 16:51
Hi Are there any proper examples, where I want to verify my contract at producer side using gradle with pact broker having some setup(like adding authorization headers), i tried using the documentation , but it did not worked, it always gave me unauthorized

komeershettyvinod
2020-09-15 16:51
any proper examples would be helpful

komeershettyvinod
2020-09-15 17:11
My sample code is

komeershettyvinod
2020-09-15 17:11
how to re-write this , can any 1 please help

komeershettyvinod
2020-09-15 17:11
Thanks

matt.fellows
2020-09-16 00:07
@komeershettyvinod I?ve deleted that code snippet as you pasted credentials

matt.fellows
2020-09-16 00:07
could you please try again with any credentials redacted?

matt.fellows
2020-09-16 00:07
I?d also suggest you rotate your API credentials for your Pactflow account immediately

komeershettyvinod
2020-09-16 04:52
@matt.fellows ah I missed changing the creds there, anyways did you got my prblm what I am trying to say?

matt.fellows
2020-09-16 04:59
I didn?t I?m afraid. Unfortunately I don?t know the gradle interface all that well

matt.fellows
2020-09-16 05:00
feel free to share again, and perhaps somebody else will know better!

francislainy.campos
2020-09-16 07:55
Hi, is it possible to assert for an empty array? I just want to make sure the key is there. Thank you.

matt.fellows
2020-09-16 07:57
Yes, you should be able to

matt.fellows
2020-09-16 07:57
but if data comes back in the response, it will fail

francislainy.campos
2020-09-16 08:03
Hi Matt, good morning. Thank you for the reply. It shouldn't come back no, but when I use `eachLike(participants) closeArray` it creates me an array with an empty object inside rather than an empty array.

francislainy.campos
2020-09-16 08:04
So `participants [{}]` rather than `participants []`

wesleythomaswilliams
2020-09-16 08:37
Would this work? ```.array(pacticipants) .closeArray()```

francislainy.campos
2020-09-16 08:49
Yeah, that's it exactly! Worked perfectly. Thanks a lot Wes!! :slightly_smiling_face: :slightly_smiling_face:

wesleythomaswilliams
2020-09-16 08:49
Haha, good guess on my part :smile:

young
2020-09-17 01:35
has joined #pact-jvm

sathisan
2020-09-17 10:09
Hi everybody, I am trying to set up Contract testing for https server. For the Consumer Test, I could find the following example: @Rule public PactProviderRule mockTestProvider = new PactProviderRule("test_provider", "localhost", 8443, true, "/path/to/your/keystore.jks", "your-keystore-password", PactSpecVersion.V2, this); Is this still supported? If there are any Updates for contract testing with https, i would appreciate any help

matt.fellows
2020-09-17 10:26
I can?t comment on how to setup the JVM tests, but just triple check that you actually really need to do https on the consumer side _test_ - there is rarely a good reason to do it, the only one that springs to mind is a really inflexible client code base that means switching out the protocol is really hard to do or there is a stupid organisational policy preventing http interactions (even in local dev)

matt.fellows
2020-09-17 10:26
https doesn?t add anything valuable to the contract test, but it may complicate it

sathisan
2020-09-17 10:50
Hi Matt, Thank you for your Feedback, . I tried the whole setup ignoring the security context. Bu the Problem on the provider Side was that I get an Error that request Processing failed. Userdetails is a Parameter Read from the certificate used for https and is used as a Parameter for my provider, but in provider Side it fails because of this parameter

mmotornyi.consultant
2020-09-17 11:44
has joined #pact-jvm

mmotornyi.consultant
2020-09-17 11:45
Does anybody have an example of Koltin + Gradle project with contract tests?

christopher.lampert
2020-09-17 12:07
has joined #pact-jvm

matt.fellows
2020-09-17 12:49
interesting

matt.fellows
2020-09-17 12:49
I may be wrong here, so hopefully somebody else can clarify, but I don?t think you can capture aspects of the certificate in the contract

matt.fellows
2020-09-17 12:50
I think what you need is to setup a custom security context on the provider verification step (use SSL there with a custom certificate), or to relax the authentication for the provider setup (e.g. stub out some behaviour) during test

matt.fellows
2020-09-17 12:50
you might be in the edge case scenario here


mmotornyi.consultant
2020-09-17 14:00
Nice! Thnx a lot!

saurabhapd
2020-09-17 15:27
has joined #pact-jvm

abubics
2020-09-17 23:41
Oh wow... I might have newer Android tests in Kotlin, but they'll still be >1 year old.

matt.fellows
2020-09-18 02:31
Thanks past Boris :stuck_out_tongue:

mmotornyi.consultant
2020-09-18 06:57
@abubics Are your tests available in public repo?

abubics
2020-09-18 07:13
oh, no . . . only the ones Matt linked earlier

tjones
2020-09-18 07:14
(@mmotornyi.consultant, the code Matt linked above was written by @abubics)

abubics
2020-09-18 07:14
I've posted them in this Slack workspace before, but I guess they're lost to the free message limit

abubics
2020-09-18 07:15
I can dig them up and post them again here :slightly_smiling_face:

abubics
2020-09-18 07:15
Oh right, I see . . . the consumer in that repo is a tiny groovy class

abubics
2020-09-18 07:15
gimme a sec

tjones
2020-09-18 07:16
Taco for @abubics :taco: !

abubics
2020-09-18 07:20
So, I had a base Pact test class for reusable helpers: ```open class PactBase : StringSpec() { val builder: PactDslWithProvider = ConsumerPactBuilder .consumer("MyRedacted Android") .hasPactWith("MyRedacted BFF") private val authToken = "valid_token" val getToken = { authToken } val authHeaders = mapOf("Authorization" to "Bearer $authToken") val contentTypeHeaders = mapOf("Content-Type" to "application/json;charset=utf-8") val firebase: Firebase? = null fun verify(pact: RequestResponsePact, func: MyRedactedConnector.() -> Unit) { val config = MockProviderConfig.createDefault() val result = runConsumerTest(pact, config, object : PactTestRun { override fun run(mockServer: MockServer) { buildMyRedacted(mockServer.getUrl(), getToken, firebase).func() } }) result shouldBe PactVerificationResult.Ok } companion object { const val GET = "GET" const val POST = "POST" } }```

abubics
2020-09-18 07:21
And then tests like this: ```class PactAccountTests : PactBase() { init { "fetches Accounts and converts them to AccountReferences" { val pact = builder .given("a member with some accounts") .uponReceiving("a request for the list of all accounts").run { headers(authHeaders) method(GET) path("/member/12345/account") } .willRespondWith().run { headers(contentTypeHeaders) status(200) body(newJsonBody { container -> with(container) { minArrayLike("accounts", 1) { with(it) { stringType("id", "S01-01") stringType("name", "Access Account TestOne") stringMatcher("type", "savings|investment|loan", "savings") numberType("availableBalance", BigDecimal("5.00")) numberType("currentBalance", BigDecimal("5.67")) } } } }.build()) } .toPact() verify(pact) { fetchAccountList( AccountsRequest( userId = "12345" ) ) shouldBe Response.Success( listOf( AccountReference( id = "S01-01", type = AccountType.Savings, name = "Access Account TestOne", availableBalance = BigDecimal("5.00"), currentBalance = BigDecimal("5.67") ) ) ) } } ...```

abubics
2020-09-18 07:22
It would be nice to turn this into a generic sample with a full app & build structure

abubics
2020-09-18 07:22
But this is the core of the pertinent bits, anyway :pray:

mmotornyi.consultant
2020-09-18 07:23
Great, thanks! I need to sort out all the things

abubics
2020-09-18 07:25
all g, ping us again if you have any other questions/issues ^_^ the weekend is just starting here (almost 5:30pm on Friday), but people should still be available for a few hours :innocent:

abubics
2020-09-18 07:25
This sample is using the java8 DSL, but I think there's a Kotlin DSL now, too

sathisan
2020-09-18 08:02
Hi everyone, Can someone Please tell me if this Consumer Test with pact JvM for https is still up-to-date? I could Not Retrieve the PactproviderRule used in this example with path and password of the keystore https://github.com/DiUS/pact-jvm/blob/master/consumer/junit/src/test/java/au/com/dius/pact/consumer/junit/pactproviderrule/PactProviderHttpsKeystoreTest.java

uglyog
2020-09-18 08:25
That example is on the master branch, which corresponds to version 4.1.7

sathisan
2020-09-18 09:21
Hi Ron, Thank you for your answer, do Dou have an example for using Pact for verifying HTTPS endpoint ?

sathisan
2020-09-18 09:24
I found the PactHttpsProviderRule with different implementations, but only the One which contains https boolean flag seems to set up a Mockhttps Server? Where ja the difference between PactproviderRule and PactHttpsProviderRule without containing the https boolean flag ?

francislainy.campos
2020-09-18 09:25
Hi, not sure your specific needs but all our endpoints are https and this is how we do it here from our side. ```@Provider(VC) /** Uncomment this and comment @PactBroker instead to test locally by pasting a .json file for the contract under the target/pacts folder */ @PactFolder("target/pacts") public class PactProviderTest { @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactTestTemplate(PactVerificationContext context, HttpRequest request) { request.addHeader("Authorization", AUTHORIZATION_TOKEN); context.verifyInteraction(); } @BeforeEach void before(PactVerificationContext context) { context.setTarget(new HttpsTestTarget(getBasePactEndpoint(), 443, "/")); getAuthorizationToken(UserType.TEACHER); } @State("A request to retrieve the meeting list for a user") public void sampleState() { } }```

sathisan
2020-09-18 09:58
Thank you Francislainly Can you also Show me the corresponding the Consumer Test, currently I am stuck at setting up the Consumer Test for accessing the https Mock Server?

francislainy.campos
2020-09-18 09:58
```import au.com.dius.pact.consumer.dsl.DslPart; import au.com.dius.pact.consumer.dsl.PactDslJsonBody; import au.com.dius.pact.consumer.dsl.PactDslWithProvider; import au.com.dius.pact.consumer.junit5.PactConsumerTestExt; import au.com.dius.pact.consumer.junit5.PactTestFor; import au.com.dius.pact.core.model.RequestResponsePact; import au.com.dius.pact.core.model.annotations.Pact; import io.restassured.RestAssured; import io.restassured.specification.RequestSpecification; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; import static com.hmhco.vcservice.config.Constants.ED_UI; import static http://com.hmhco.vcservice.config.Constants.VC; /** * * mvn -Dtest=com.hmhco.vcservice.pact_tests.consumer.*Test test */ @ExtendWith(PactConsumerTestExt.class) public class PactConsumerTest { Map<String, String> headers = new HashMap<>(); String storeMeetingPath = "/vcservice/store/meeting"; DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); String nowAsISO = df.format(new Date()); @Pact(provider = VC, consumer = ED_UI) public RequestResponsePact createPact(PactDslWithProvider builder) throws ParseException { headers.put("Content-Type", "application/json"); headers.put("Accept", "application/json"); DslPart bodyReceivedStoreMeetingList = new PactDslJsonBody() .integerType("totalMeetings", 3) .integerType("totalPages", 1) .integerType("pageSize", 20) .integerType("pageNumber") .eachLike("meetings") .integerType("id", 93) .stringType("title", "My new title") .date("startDateTime", "yyyy-MM-dd'T'HH:mm:ss'Z'", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").parse(nowAsISO)) .integerType("duration", 0) .stringType("attributes", "string") .stringType("provider", "ZOOM") .object("creator") .integerType("id", 1) .stringType("hmhUserRefId", "d7af5c68-fcee-4eab-8977-1d800a8b818e") .object("attributes") .closeObject() .closeObject() .array("participants") .closeArray(); return builder .given("A request to retrieve the meeting list for a user") .uponReceiving("A request to retrieve the meeting list for a user") .path(storeMeetingPath) .method("GET") .headers(headers) .willRespondWith() .body(bodyReceivedStoreMeetingList) .status(200) .toPact(); } @Test @PactTestFor(providerName = VC, port = "8080") public void runTest() { //Mock url RestAssured.baseURI = "http://localhost:8080"; RequestSpecification rq = RestAssured .given() .headers(headers) .when(); rq.get(storeMeetingPath); } }```

francislainy.campos
2020-09-18 09:59
Sure, here you go.


francislainy.campos
2020-09-18 10:00
And here an article I recently wrote talking about how we do Pact here from our side.

sathisan
2020-09-18 11:01
Thank you will go through these materials, i was Sticking to pact JvM with junit 4

francislainy.campos
2020-09-18 11:18
Yeah, I think better to do it with junit5 as more current.


abubics
2020-09-18 12:42
:taco: to @francislainy.campos for being a great helper buddy while also still being a fresh face :tada:

francislainy.campos
2020-09-18 12:44
Haha, thank you! Always good to get something to eat at lunch time. :wink:

sathisan
2020-09-18 12:44
@francislainy.campos One question regarding your Consumer test: If you want to test an HTTPS endpoint, why didn't you Set the https=True on the @PactTestFor annotation?

francislainy.campos
2020-09-18 12:45
I didn't need this as it worked regardless.

francislainy.campos
2020-09-18 12:45
To be honest, first time I see the mention of using this..

sathisan
2020-09-18 12:47
It is recommended doing so in the pact documentation for junit5: Using HTTPS# You can enable a HTTPS mock server by setting https=true on the @PactTestFor annotation. Note that this mock server will use a self-signed certificate, so any client code will need to accept self-signed certificates.Using HTTPS# You can enable a HTTPS mock server by setting https=true on the @PactTestFor annotation. Note that this mock server will use a self-signed certificate, so any client code will need to accept self-signed certificates.

francislainy.campos
2020-09-18 12:50
Uhhmm, well, we're verifying against our real https endpoints when triggering through the provider side.

francislainy.campos
2020-09-18 12:50
Not sure still why we'd needed to do a mocking using self signed certificates if that's not the real testing.

francislainy.campos
2020-09-18 12:53
I could be wrong but as far as I see it, the mock server on the consumer side is just to validate the contract has been set properly.

sathisan
2020-09-18 12:55
Yes agree with you, thank you :relaxed::+1:

phil.endsley
2020-09-18 13:15
Try using `.pathFromProviderState` on the consumer. That will let you template the id (with a default value) on the consumer. When your provider state is executed, it can create a new id, and inject that into the url before the request is made. The provider state method then just needs to return a map with the key and value Consumer: https://github.com/DiUS/pact-jvm/tree/master/consumer#having-values-injected-from-provider-state-callbacks Provider: https://github.com/DiUS/pact-jvm/tree/master/provider/junit#returning-values-that-can-be-injected

francislainy.campos
2020-09-18 13:28
:clap:

francislainy.campos
2020-09-18 13:29
That's so cool! Thanks Phil, that worked perfectly. I'll update my so question with the answer for this.

francislainy.campos
2020-09-18 13:29
```@State("A request to retrieve a Zoom meeting with one participant") public Map sampleState() { Map<String, Integer> map = new HashMap<>(); map.put("id", 391); return map; }```

francislainy.campos
2020-09-18 13:30
```return builder .given("A request to retrieve a Zoom meeting with one participant") .uponReceiving("A request to retrieve a Zoom meeting with one participant") .pathFromProviderState("/vcservice/store/meeting/${id}", "/vcservice/store/meeting/500") .method("GET")```

francislainy.campos
2020-09-18 13:39
Update done.

komeershettyvinod
2020-09-18 15:39
can we achieve same through gradle?

komeershettyvinod
2020-09-18 15:39
Thanks for asking this @francislainy.campos




komeershettyvinod
2020-09-18 16:06
consumer side its fine

komeershettyvinod
2020-09-18 16:26
i dont see example at provider side i.e how to declare/use

komeershettyvinod
2020-09-18 16:26
:disappointed:

phil.endsley
2020-09-18 16:29
I haven't used the gradle stuff, but it looks like it should work the same. Just return a map of {templateKey: value} from the provider state callback. Where templateKey is the same variable name used from the consumer template

komeershettyvinod
2020-09-18 16:39
How to return a

komeershettyvinod
2020-09-18 16:40
service { given('User harry exists') uponReceiving('a request for user harry') withAttributes(method: 'get', path: fromProviderState('/api/user/${id}', '/api/user/100')) withBody { name(fromProviderState('userName', 'harry')) // looks up the value using the userName key }

komeershettyvinod
2020-09-18 16:40
how to return a path here

komeershettyvinod
2020-09-18 16:41
from build.gradle , can you share small snippet how to achieve plz

phil.endsley
2020-09-18 16:41
That's from the consumer. The first link I sent has a code snippet

phil.endsley
2020-09-18 16:42
```service { given('User harry exists') uponReceiving('a request for user harry') withAttributes(method: 'get', path: fromProviderState('/api/user/${id}', '/api/user/100')) withBody { name(fromProviderState('userName', 'harry')) // looks up the value using the userName key } }```

phil.endsley
2020-09-18 16:43
Ah. Didn't realize that's what you posted as well... ```withAttributes(method: 'get', path: fromProviderState('/api/user/${id}',``` Isn't that what this is doing?

komeershettyvinod
2020-09-18 17:00
No issues with consumer side I am using exactly this way

komeershettyvinod
2020-09-18 17:01
How to call from producer side?

komeershettyvinod
2020-09-18 17:01
in gradle

phil.endsley
2020-09-18 17:12
I'm not very confident with groovy, so this may not work :sweat_smile: But I would think something like: ```stateChange = { providerState -> // providerState is an instance of ProviderState def fixture = loadFixtuerForProviderState(providerState) setupDatabase(fixture) {"id": 123} }``` Is what you would want to use a value of 123 for {id} I just tweaked the example from https://github.com/DiUS/pact-jvm/tree/master/provider/gradle#using-a-closure If this doesn't work, might need to just experiment or wait for @uglyog or someone else that's done it

komeershettyvinod
2020-09-18 17:23
is loadFixtuerForProviderState and setupDatabase are predefined?

phil.endsley
2020-09-18 17:24
No. You can remove those lines. Presumably, those are separate functions that would actually configure the provider state and set up the database with seed data, respectively

uglyog
2020-09-19 02:01
@phil.endsley has it correct

matt.fellows
2020-09-20 11:48
@phil.endsley :taco:

matt.fellows
2020-09-20 11:51
@francislainy.campos please help yourself to a :taco: for answering on SO

young
2020-09-21 07:15
Hi Pact team, where should I add the './gradlew pactVerify' action to the Provider in a deploy pipeline? position1, or position 2? I think the position 1 is preferred, any suggestions? Thanks.

matt.fellows
2020-09-21 07:18
I?d run it as part of the test phase, so (1)

young
2020-09-21 07:20
Thank you @matt.fellows

sathisan
2020-09-21 07:57
@francislainy.campos I tried the same setup like you, but currently have some issue with the certification Is the port 443 you give as Parameter the same One where your actual Application will listen to it ?

francislainy.campos
2020-09-21 10:04
No, 443 is just a number so that it doesn't generate random ones. I think it may not make much difference which one to use.

francislainy.campos
2020-09-21 10:07
Are you verifying against your hosted remote service? Are you able to do any other type of test against it? Maybe not an issue with Pact but something else? Can you trigger your apis from Postman? Can you do functional tests using Rest Assured or other? Which specific error do you get?

francislainy.campos
2020-09-21 10:12
Hi, good morning. Sorry, same question as last week but for an object rather than an array. Wanting to verify whether the key is there regardless of whether it's coming back as null. Thank you.

francislainy.campos
2020-09-21 10:16
Found it here!

francislainy.campos
2020-09-21 10:16
```.nullValue("attributes")```

sathisan
2020-09-21 11:21
I get a Connection refused Error, and could Not figure out why

francislainy.campos
2020-09-21 11:22
But why you're using localhost as the target?

francislainy.campos
2020-09-21 11:22
It should be the url you're testing against..

francislainy.campos
2020-09-21 11:24

francislainy.campos
2020-09-21 11:24
Like this, and without the https at the beginning.

sathisan
2020-09-21 11:31
There are different implementations of HttpsTestTarget, the One i Posted earlier is the One containing Host and port As the URL i am testing is: https://localhost:8448/auth/getTribeList?password=F67617, i Set my Host as localhost and port i Set randomly as you told

francislainy.campos
2020-09-21 11:32
I'm not sure how to test against localhost if this is not a url that is hosted outside your local computer.

francislainy.campos
2020-09-21 11:33
There may be a way but never done that and not sure why you need it this way?

francislainy.campos
2020-09-21 11:33
Is your api not hosted remotely?

sathisan
2020-09-21 11:39
The contract testing is applied here to test the REST APIs of the application itself Since it will be a microservices reference Application, they want to introduce contract testing as it is an additional Layer of testing in a microservices application

francislainy.campos
2020-09-21 11:44
Okay, maybe better to ping @matt.fellows or @phil.endsley in case they can better advise you. I'm not sure what you mean by testing the application itself, you mean, prior to deployment? Wouldn't they have a dev environment they could deploy against and verify it this way so that you'd still have access to a hosted url? Otherwise, I'm not sure how to do this connection to a localhost. The issue here doesn't seem to be Pact itself but this part.

francislainy.campos
2020-09-21 11:47
As far as I understand it, Pact comes as part of the integration layer, so not the same as unit tests which seems to be how you guys may be intending to use it.

sathisan
2020-09-21 11:47
I Test the correctness of the messages from the REST APIs in my Application, so i am using pact to check the interaction between the webclient and the apis

francislainy.campos
2020-09-21 11:48
Yeah, but I think you could do this outside localhost no?

francislainy.campos
2020-09-21 11:49
What is the url your consumers use? This is the one I think you should be using.

sathisan
2020-09-21 11:50
So far it Not deployed and only accessible via localhost

francislainy.campos
2020-09-21 11:52
Okay, yeah, I'm not sure how to do this connection through a localhost myself. Sorry, it may be possible, but never done it.

francislainy.campos
2020-09-21 11:53
Maybe wait till one of the guys can jump in on this thread or someone else or even post another question, asking how to do pact against localhost, since this is what you seem to be wanting.

sathisan
2020-09-21 11:53
Thank you for your help, Great article, i like your writing style, was Interactive while reading

francislainy.campos
2020-09-21 11:55
Thank you. Appreciate it. Sorry that couldn't help much more here. I'll try to write some more as I'm also learning and it's good to share so we can help each other.

francislainy.campos
2020-09-21 11:55
I'll keep checking on this thread if you can find the solution as would be curious to see what to do for your specific scenario.

francislainy.campos
2020-09-21 11:59
Ah! wait, thinking here now. Is your application running while you're trying to run your pact tests? Could this be the issue if it is not? I mean, within the same IntelliJ project are you able to trigger the same request you're trying to verify against using Pact?

francislainy.campos
2020-09-21 12:06
If you try the same api on postman is it working?

sathisan
2020-09-21 12:09
Yes i Run my pact tests while my Application was Running, but does it matter ? The Application context is generated while executing But for my use Case, i found a Good example in the repo: package au.com.dius.pact.provider.junit5; import au.com.dius.pact.provider.junitsupport.Provider; import au.com.dius.pact.provider.junitsupport.State; import au.com.dius.pact.provider.junitsupport.loader.PactFolder; import com.github.tomakehurst.wiremock.WireMockServer; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestTemplate; import org.junit.jupiter.api.extension.ExtendWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import ru.lanwen.wiremock.ext.WiremockResolver; import ru.lanwen.wiremock.ext.WiremockUriResolver; import java.util.Map; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static java.lang.String.format; @Provider("myAwesomeService") @PactFolder("pacts") @ExtendWith({ WiremockResolver.class, WiremockUriResolver.class }) public class HttpsContractTest { private static final Logger LOGGER = LoggerFactory.getLogger(HttpsContractTest.class); @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void testTemplate(PactVerificationContext context) { context.verifyInteraction(); } @BeforeEach void before(PactVerificationContext context, @WiremockResolver.Wiremock(factory = WiremockHttpsConfigFactory.class) WireMockServer server) { // Rest data // Mock dependent service responses // ... http://LOGGER.info("BeforeEach - " + server.httpsPort()); context.setTarget(new HttpsTestTarget("localhost", server.httpsPort(), "/", true)); server.stubFor( get(urlPathEqualTo("/data")) .willReturn(aResponse() .withStatus(204) .withHeader("Location", format("http://localhost:%s/ticket/%s", server.port(), "1234") ) .withHeader("X-Ticket-ID", "1234")) ); } @State("default") public void toDefaultState() { // Prepare service before interaction that require "default" state // ... http://LOGGER.info("Now service in default state"); } @State("state 2") public void toSecondState(Map params) { // Prepare service before interaction that require "state 2" state // ... http://LOGGER.info("Now service in 'state 2' state: " + params); } }

francislainy.campos
2020-09-21 12:36
Yeah, I think it would matter otherwise there wouldn't be a response to be verified against.

phil.endsley
2020-09-21 12:51
@sathisan Are you still having issues? And if so, what are they? Testing against localhost is perfectly fine, and is what I encourage. That way, you can run verifications as part of your build pipeline, and you don't have to wait for your application to deploy before running verifications.

sathisan
2020-09-21 14:22
Hi @phil.endsley Thank you for your Feedback I found the Code i Posted above for contract testing with https and junit5. Maybe if you are familiar, you can help me with the following questions: Why do we need to inject a mockserver, is it Not possible to verify against the Running Application if i have an Https endpoint?

phil.endsley
2020-09-21 14:41
I don't think you need to. The example you found is in the unit testing package of the jvm pact source code. I'm pretty sure this is actual tests for the library itself to ensure it all works as expected. Back to your earlier comment: > i Set my Host as localhost and port i Set randomly as you told The port you use should match the port of your running application. Just making sure you're setting that to the actual port being used, and not a random number. > As the URL i am testing is: https://localhost:8448/auth/getTribeList?password=F67617, If 8448 is always the port being used when your provider tests are ran, you should set the port to 8448 on https target

phil.endsley
2020-09-21 14:45
I haven't done any pact tests with https, because we don't have that need. One assumption I'm making, is when your application is running on localhost for your tests, you're serving it over https with tls certificates. If your tests are not starting your application on localhost with tls, you don't need https for your pacts. You may already know this, just want to reiterate that point.

sathisan
2020-09-21 15:51
Thank you @phil.endsley I am Not Sure if I understand your point correctly, but in my use Case the endpoints do Not get invoked if I use httptarget, always get 400 status,because the certificates used for https authorise the User for invoking the endpoint. And Now if I use your setup as suggested, I get a message about the certification.

phil.endsley
2020-09-21 15:52
What message about certification?

phil.endsley
2020-09-21 15:55
Can you put the whole reason here? You can remove proprietary info if need be Looks like the error message is "Unable to find..."

sathisan
2020-09-21 15:57
i am unable to Copy and paste

francislainy.campos
2020-09-21 15:58
Hi, what would be the best way to have the body passed as params for my post api as specified on the consumer contract printed back to me when verifying it from the provider side please. Thought it would be there under the interaction object but it doesn't seem to be the case.

sathisan
2020-09-21 16:00
Hope you can still read it, would appreciate any help I am Not Sure is, the certificate used for application needs to be created once again for Test purposes to invoke my endpoint ?

phil.endsley
2020-09-21 16:03
Yeah, no problem. So good news and bad news. Good news: it looks like the pact stuff is all working correctly. Your test runs, it finds interactions, and looks like a request is being made to the provider. Bad news: This doesn't look like a pact problem, so help here may be limited...

phil.endsley
2020-09-21 16:04
My guess is your application instance when running tests is not correctly setting up the certificates

phil.endsley
2020-09-21 16:04
Like you said, if you're not configuring the certificates for your tests, that's something you need to do

phil.endsley
2020-09-21 16:13
It's probably under interaction.request At this point in the flow, the http request has already been made, so the request body you specified should be part of the request object

francislainy.campos
2020-09-21 16:22
Thanks a lot, Phil. Yeah, that worked.

sathisan
2020-09-21 16:23
The certificate is already in use for application, and for Test purposes I Need to have corresponding certificates to invoke the endpoint I can overcome these issues with the mvctesttarget right?

phil.endsley
2020-09-21 16:36
I'm not sure what mvctesttarget would give you that whatever you're using now doesn't. As I understand it, the issue you're running into now seems to be that your mechanism for authenticating users is not setup/configured correctly for your provider tests. If you have to have that working, and it works by using certificates, I don't see a way around it without using certificates with your tests

phil.endsley
2020-09-21 16:37
It's been hinted at a few times, but if you can mock out/bypass the auth process when running your provider tests locally, you can probably bypass the https requirement. Sometimes, this is not possible though, and it's completely dependent on your individual use case. https://docs.pact.io/provider/handling_auth/

sathisan
2020-09-21 19:58
Hi @phil.endsley Thank you for your help, Really appreciate it the mvc setup supports the use @ WithMockUser which mocks the authentication

francislainy.campos
2020-09-21 20:02
That's really great it seems to be working for you now, Sathish. Well done! Could you share the full code for your provider as would be interested in having a look at your final working implementation if it's okay with you.

sathisan
2020-09-21 20:58
Thank you Francislainly :relaxed: Will summarize my approach and present it in the channel

abubics
2020-09-22 00:02
:taco: for @phil.endsley, who has the patience of a saint :innocent:

phil.endsley
2020-09-22 00:51
You're too kind :grin: I just like helping people

kflo
2020-09-22 01:18
has joined #pact-jvm

aaron.ramirez
2020-09-22 03:35
has joined #pact-jvm

francislainy.campos
2020-09-22 10:59
```public static void logCurlFromPact(PactVerificationContext context, HttpRequest request) throws IOException { String bodyParam = ((RequestResponseInteraction) context.getInteraction()).getRequest().getBody().valueAsString(); http://log.info(bodyParam); String bodyResponse = ((RequestResponseInteraction) context.getInteraction()).getResponse().getBody().valueAsString(); String method = ((RequestResponseInteraction) context.getInteraction()).getRequest().getMethod(); String baseUrl = ""; if (method.equals("POST")) { baseUrl = ((HttpPost) request).getURI().toString(); } else if (method.equals("GET")) { baseUrl = ((HttpGet) request).getURI().toString(); } Header[] headers = request.getAllHeaders(); String headersString = ""; for (Header s : headers) { headersString = headersString + "--header " + "'" + s.getName() + ": " + s.getValue() + "'" + "\\" + "\n"; } String curl = "" + "curl " + "'" + baseUrl + "' \\" + "\n" + headersString + "--data-binary " + "'" + bodyParam + "' \\" + "\n" + "--compressed \\" + "\n" + "--insecure \\" + "\n" + "--verbose" + ""; System.out.println(curl + "\n\n " + bodyResponse + " \n ---- \n"); }```

francislainy.campos
2020-09-22 11:02
```@TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactTestTemplate(PactVerificationContext context, HttpRequest request) throws IOException { request.addHeader("Authorization", AUTHORIZATION_TOKEN); logCurlFromPact(context, request); context.verifyInteraction(); }``` There may be better ways to do this but got this method working when wanting to print a curl for my Pact tests.


francislainy.campos
2020-09-22 11:17
Turned it a SO post in case helpful to someone else.

giuseppe.salvatore
2020-09-22 12:48
Hi everyone, I am having a slightly annoying problem I have not been able to figure out how to solve Consumer is pact-jvm, Provider is node-js In the contract the Consumer is publishing, the response header has ```"headers": { "Content-Type": "application/json; charset=UTF-8" }``` but when the node-js service verifies the contract it produces ```"Content-Type": "application/json; charset=utf-8"``` (note utf in lowercase) Is there a way to perform a case insensitive match? I was trying to change the way the consumer produces the response so that it could have it as lower case but using the RestTemplate I don't seem to be able to change that in the response

matt.fellows
2020-09-22 13:04
I'm not sure. A regex matcher may be able to do it with a case insensitive check. I would just use a regex matcher that checks for the content type and ignores the charset parameter See also https://github.com/pact-foundation/pact-specification/tree/version-3

giuseppe.salvatore
2020-09-22 13:05
yeah the problem is that on the provider side it looks to me like the verification is ran automatically with very little input from me

giuseppe.salvatore
2020-09-22 13:09
but I can see there are links with similar discussions around the Content-Type failures.... I will take a look at it

giuseppe.salvatore
2020-09-22 13:09
thanks @matt.fellows always useful stuff!!

giuseppe.salvatore
2020-09-22 13:19
Ahh... now I understand what you mean Matt!! It makes sense, I just need to find how to do it

giuseppe.salvatore
2020-09-22 15:37
@matt.fellows looks like I managed to make a bit of progress and to express the content-type as a regex in the response

giuseppe.salvatore
2020-09-22 15:37
```pactRequestWithPath .willRespondWith() .matchHeader("Content-Type", "application/json; charset=(utf|UTF)-8") .status(200)```

giuseppe.salvatore
2020-09-22 15:38
which in fact produces

giuseppe.salvatore
2020-09-22 15:38
```"matchingRules": { "header": { "Content-Type": { "matchers": [ { "match": "regex", "regex": "application/json; charset=(utf|UTF)-8" } ], "combine": "AND" } },```

giuseppe.salvatore
2020-09-22 15:38
which seems to be correct

giuseppe.salvatore
2020-09-22 15:39
but for some reasons it looks like it keeps complaining with the same error

giuseppe.salvatore
2020-09-22 15:39
on the provider

giuseppe.salvatore
2020-09-22 15:39
and if I provide an example in the matchHeader function

giuseppe.salvatore
2020-09-22 15:40
```.matchHeader("Content-Type", "application/json; charset=(utf|UTF)-8", "application/json; charset=UTF-8")```

giuseppe.salvatore
2020-09-22 15:40
like the above it fails

giuseppe.salvatore
2020-09-22 15:41
```.matchHeader("Content-Type", "application/json; charset=(utf|UTF)-8", "application/json; charset=utf-8")```

giuseppe.salvatore
2020-09-22 15:41
with this example instead succeeds

giuseppe.salvatore
2020-09-22 15:41
seems to me like it's ignoring the regex and going straight to the example

giuseppe.salvatore
2020-09-22 15:48
your idea was good and thought it would have worked :confused:

uglyog
2020-09-22 22:50
This needs to be fixed in pact-js. I've had this issue as well and it is annoying. Can you raise an issue on the Pact-JS project?

matt.fellows
2020-09-23 01:23
I?d say it is the way the underlying Ruby binary interprets the regex

matt.fellows
2020-09-23 01:23
Might be doable, but I recall regexes being funny in Ruby

matt.fellows
2020-09-23 01:23
in any case, please raise an issue and we?ll look at it

matt.fellows
2020-09-23 01:24
I would do this for the time being (ignore the charset in the regex for now, unless it?s really important): ```.matchHeader("Content-Type", "application/json", "application/json; charset=utf-8")```

uglyog
2020-09-23 01:25
Not a problem with regex, problem with matching headers

uglyog
2020-09-23 01:26
It should accept `application/json; charset=UTF-8` and `application/json; charset=utf-8`

uglyog
2020-09-23 01:26
They are the same value

giuseppe.salvatore
2020-09-23 07:42
ok thanks guys I will raise a bug in JS project :+1:

komeershettyvinod
2020-09-23 16:16
Does pact 4.1.x requires junit 5 version as a pre-req

komeershettyvinod
2020-09-23 16:17
I want to use 4.1.x but already whole lot of tests are dependent on junit 4

komeershettyvinod
2020-09-23 16:17
in my framewrk

komeershettyvinod
2020-09-23 16:18
I want to know if 4.1.x works with junit 4 as well?

phil.endsley
2020-09-23 16:44
It works with both. There are separate libraries you can import depending on which one you want (junit 4 vs 5)

mbbush
2020-09-23 22:18
has joined #pact-jvm


francislainy.campos
2020-09-24 07:27
I had the same issue when started with Pact and here how it got solved. You can run both JUnit4 and 5 on the same project using a most recent version for the maven surefire plugin.

christiaan
2020-09-24 08:31
has joined #pact-jvm

giuseppe.salvatore
2020-09-24 09:52
@uglyog @matt.fellows sorry it took so long


christiaan
2020-09-24 10:56
Hi all.  Two newbie questions: 1) Can somebody explain me the actual reason/rational about why when you use maven that, after running your unit tests, the producer needs to verify the pact in a seperate step "`mvn pact:verify"` against a running provider?  2 If my producer application already exdcutes junit in the "normal maven verify goal", which is also triggered during e.g mvn clean install, can I then skip this "`mvn pact:verify"` alltogether?

wesleythomaswilliams
2020-09-24 11:32
Hi Christiaan, not sure I can answer the question specifically, more talk about our configuration. Our junit tests do the verification, so we don't use pact:verify. See the note in the attached image from the below link.


matt.fellows
2020-09-24 11:44
Just closing out the thread here for those not following the GH issue - TL;DR - the pact is a v3 generated Pact, and Pact JS currently supports 2. See ticket for more

christiaan
2020-09-24 12:06
Thanks Wes for replying. I saw this passage indeed. So this means that if my application uses junit as wel as maven, then I do not have to use pact:verify. Check!

phil.endsley
2020-09-24 12:33
Correct! You just have to set a system property to make sure you're publishing the results. https://docs.pact.io/implementation_guides/jvm/provider/junit/#publishing-verification-results-to-a-pact-broker

adrianojedabenitez
2020-09-24 13:01
has joined #pact-jvm

komeershettyvinod
2020-09-24 13:54
Provider Test

komeershettyvinod
2020-09-24 13:54
import http://au.com.dius.pact.provider.junit.Consumer import http://au.com.dius.pact.provider.junit.Provider import http://au.com.dius.pact.provider.junit.State import http://au.com.dius.pact.provider.junit.loader.PactBroker import http://au.com.dius.pact.provider.junit.loader.PactBrokerAuth import http://au.com.dius.pact.provider.junit5.HttpTestTarget import http://au.com.dius.pact.provider.junit5.PactVerificationContext import http://au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider import org.apache.http.HttpRequest import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.TestTemplate import org.junit.jupiter.api.extension.ExtendWith @Provider("A Service") @PactBroker(host = "xxxx", authentication = @PactBrokerAuth(token = "dfgxx5tA8J0viAUfzOOZldrsAzzzzzzzzzz")) @Consumer("B Service") public class ProviderTest { @BeforeEach void before(PactVerificationContext context) { context.setTarget(new HttpTestTarget("localhost", 8084, "/")); } @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactTestTemplate(PactVerificationContext context, HttpRequest request) { request.addHeader("Authorization", ApiUtil.getAuthorizationToken()); request.addHeader('X-Auth-Scheme', 'CERBERUS') context.verifyInteraction(); } @State("test Get call marketing plan details") public def sampleState() { } @State('marketingplan details') public def sampleState1() { Map<String, String> map = new HashMap<>(); map.put("id", "123"); return map; } }

komeershettyvinod
2020-09-24 13:54
Consumer Test:

komeershettyvinod
2020-09-24 13:55
`import http://au.com.dius.pact.consumer.PactVerificationResult` import http://au.com.dius.pact.consumer.groovy.PactBuilder import groovy.json.JsonSlurper import http://groovyx.net.http.ContentType import http://groovyx.net.http.RESTClient import org.junit.Test class ContractServiceSpec1 { protected static FORECAST_DATA_JSON_FILE_PATH = '/inputs/marketingPlanData1.json' URL getResourceFile(String resourceFilePath) { this.getClass().getResource(resourceFilePath) } String readJsonFileText(String jsonFilePath) { URL jsonFile = getResourceFile(jsonFilePath) return jsonFile?.text } @Test void "Post User service test"() { String s= readJsonFileText(FORECAST_DATA_JSON_FILE_PATH) def fs= new JsonSlurper().parseText(s) print "dddd"+fs def MP_FRService = new PactBuilder() // Create a new PactBuilder MP_FRService { serviceConsumer "AService" // Define the service consumer by name hasPactWith "B Service" // Define the service provider that it has a pact with port 9000 // The port number for the service. It is optional, leave it out to given('test Get call marketing plan details') // defines a provider state. It is optional. uponReceiving('marketingplan details') // upon_receiving starts a new interaction withAttributes( path: fromProviderState('/api/v1/marketingPlanDetails/${id}','/api/v1/marketingPlanDetails/5f591924089d2c4fdc64e0bd'), method: 'get' ) willRespondWith( // define the response we want returned status: 200, headers: ['Content-Type': 'application/json'], body: fs ) } // Execute the run method to have the mock server run. // It takes a closure to execute your requests and returns a PactVerificationResult. PactVerificationResult result = MP_FRService.runTest { def client = new RESTClient('http://localhost:9000') def alice_response = client.get( path: '/api/v1/marketingPlanDetails/5f591924089d2c4fdc64e0bd') assert alice_response.status == 200 print alice_response.contentType == 'application/json' print "--------------->"+alice_response.data print "--------------->"+alice_response.responseData def data = alice_response.responseData assert data == fs } assert result == PactVerificationResult.Ok.INSTANCE // This means it is all good } // }

komeershettyvinod
2020-09-24 13:57
I was not able to pass the id from producer side to the contract file

komeershettyvinod
2020-09-24 13:58
any one can please help me what is missing :disappointed:

thomas.hibbard
2020-09-24 15:09
has joined #pact-jvm

komeershettyvinod
2020-09-24 16:48
plz ignore the msg , i was able to figure out i was using lower version

adrianojedabenitez
2020-09-25 21:36
hey dear friends! I?m facing with a weird issue, not finding any solution in the doc :sleepy:. I?m using `junit5 http://au.com.dius.pact.provider version 4.1.1 ` to build my providers pacts. The providers are being run from the build process and also when is triggered by a web-hook. I want to enable the pending contracts (because is something that we need) as per doc I?m running this command to run my verification tests ``` mvn -Dpact.verifier.publishResults=true -Dpactbroker.enablePending=true -Dpactbroker.tags=develop -Pcicdprofile clean install -s config/ci_settings.xml ``` in my code I have the next annotations. @IgnoreNoPactsToVerify // otherwise the build fails when is called from a webhook with the -Dpact.filter.pacturl filter @AllowOverridePactUrl // this as per doc to enable the Dpact.filter.pacturl (used by webhook as well) The issue with this is when I run the build from normal flow, it fails here ``` @BeforeEach void setupTestTarget(PactVerificationContext context) { context.setTarget(new HttpTestTarget(?localhost?, serverPort)); } ``` getting a NullPointer exception. Do you guys have any idea what is going on?

phil.endsley
2020-09-25 22:22
Is the npe in your before each method? If there aren't any pacts being verified, context will be null

adrianojedabenitez
2020-09-25 22:27
yup, the npe is exactly here -> context.setTarget(new HttpTestTarget(?localhost?, serverPort));

adrianojedabenitez
2020-09-25 22:28
seems that -Dpactbroker.enablePending=true causes that issue

adrianojedabenitez
2020-09-25 22:28
but I need it, because I will be able to pass the build with pending pacts

adrianojedabenitez
2020-09-25 22:31
so you mean ```HttpTestTarget("localhost", serverPort)```

adrianojedabenitez
2020-09-25 22:32
is not needed if I?m going to enable pending tests?

phil.endsley
2020-09-25 23:04
If you're getting a npe there, your provider probably isn't finding any pacts to verify. You should be able to confirm that from the logs

phil.endsley
2020-09-25 23:05
Also, if you're using enable pending pacts, you must set the provider tags property

phil.endsley
2020-09-25 23:07
pactbroker.providerTags system property

adrianojedabenitez
2020-09-26 01:50
thanks for reply buddy! yeah provider tag is defined, I?d consider the fact that there is no pact to verify but if I remove the enablePending it works.. I will research and let you know if you want.

phil.endsley
2020-09-26 01:58
When using pending pacts, if there are not any verification results published by the provider that are also tagged with whatever you define as providerTags, you won't get any pacts back... Note that providerTags I was talking about is not the same property used to tag your verification results

adrianojedabenitez
2020-09-26 02:24
wow that was fast! thanks man! will try! you are my hero!

adrianojedabenitez
2020-09-26 22:53
just as heads up, I could fix this issue as per Phil?s suggestions in the thread, but then I got the build fail (even if the test was pending) researching in the slack history I found that issue was fixed on version 4.1.3 I was using 4.1.1 just as suggestion, please update the documentation here https://www.screencast.com/t/dDSiT9GF4 so another user with version < 4.1.3 won?t have the same issue. Thanks guys!

uglyog
2020-09-26 23:28
Can you raise an issue for this on the Github project

adrianojedabenitez
2020-09-26 23:36
for sure!


dabs1234
2020-09-29 07:06
Guys I trying to test the api which needs access tocken. Following is the code ```@TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactVerificationTestTemplate(PactVerificationContext context, HttpRequest request) { request.addHeader("Authorization", "Bearer " + getClientOAuthToken()); context.verifyInteraction(); System.setProperty("pact.verifier.publishResults", "true"); }``` Getting following 400 error: 1.1) StatusMismatch: expected status of 200 but was 400 1.2) BodyMismatch: $ BodyMismatch: Expected name='name' but was missing { - "name": "name", - "id": 2000 + "timestamp": 1601355640376, + "status": 400, + "error": "Bad Request", + "message": "Missing request header 'Authorization' for method parameter of type String", + "path": "/portal/movie" } What might be wrong here? Any sample with JUnit5 would be a great help.


phil.endsley
2020-09-29 14:18
@uglyog Any chance of re-enabling notifications just for new issues created in the github repo (I'm ok with leaving PRs and everything else off)? Not sure how others feel, but I liked new issue reports for keeping a pulse on the current state of things

phil.endsley
2020-09-29 15:14
Are you using Spring Boot (Message matches, and follows the format of their responses)? What you have is what we're doing (Spring Boot with junit 5). And I just tested by adding the auth header as a parameter to the rest controller, and it still works. Pact provider test ```@TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactVerificationTestTemplate(HttpRequest request, PactVerificationContext context) { // ... irrelevant setup request.addHeader("Authorization", "Bearer someTestToken"); context.verifyInteraction(); }``` Rest controller ``` @GetMapping ResponseEntity<List<Object>> getAllThings(@RequestHeader Map<String, String> headers, @RequestHeader(value = "Authorization") String authHeader) { System.out.println("Got auth header: " + authHeader);``` In our logs: ```Verifying a pact between my-consumer and my-provider Given some state a request to do something Got auth header: Bearer someTestToken <--- From the console out above returns a response which has status code 200 (OK) includes headers "Content-Type" with value "application/json" (OK) has a matching body (OK)```

raghanag
2020-09-29 17:36
has joined #pact-jvm

uglyog
2020-09-29 23:03
Hmm, the problem would be that every comment on the issue will be posted here. But let's see what we can do.

uglyog
2020-09-29 23:03
I'll see if we can get only new notifications

phil.endsley
2020-09-29 23:12
Gotcha. If it's too noisy, I totally get it. I'm just trying to be lazy and make this a one stop shop for me

uglyog
2020-09-29 23:15
/github subscribe list

uglyog
2020-09-29 23:15
/github subscribe list features

uglyog
2020-09-29 23:18
/github subscribe DiUS/pact-jvm issues

abubics
2020-09-30 00:15
Could make a separate notifications channel if it's too noisy for most people :slightly_smiling_face:

anddreiu
2020-09-30 09:45
Hi. I've just updated the pact provider junit library in my project from 4.1.1 to 4.1.7 and it looks like I have some issues when running the provider tests for _some_ (not all of them) pact files. I get the bellow error. Using 4.1.1, it's working fine. Any hints on what could be the problem? Thanks. ```au.com.dius.pact.core.support.json.JsonException: Invalid JSON (1:2), found unexpected character '<' at au.com.dius.pact.core.support.json.JsonLexer.unexpectedCharacter(JsonParser.kt:88) at au.com.dius.pact.core.support.json.JsonLexer.nextToken(JsonParser.kt:79) at au.com.dius.pact.core.support.json.JsonParser.nextTokenOrThrow(JsonParser.kt:278) at au.com.dius.pact.core.support.json.JsonParser.parse(JsonParser.kt:151) at au.com.dius.pact.core.support.json.JsonParser.parseString(JsonParser.kt:131) at au.com.dius.pact.core.model.RequestResponseInteraction$Companion.setupBodyForJson(RequestResponseInteraction.kt:123) at au.com.dius.pact.core.model.RequestResponseInteraction$Companion.requestToMap(RequestResponseInteraction.kt:85) at au.com.dius.pact.core.model.RequestResponseInteraction.toMap(RequestResponseInteraction.kt:37) at au.com.dius.pact.provider.reporters.JsonReporter.interactionDescription(JsonReporter.kt:132) at au.com.dius.pact.provider.ProviderVerifier.reportInteractionDescription(ProviderVerifier.kt:502) at au.com.dius.pact.provider.junit.InteractionRunner.interactionBlock(InteractionRunner.kt:218) at au.com.dius.pact.provider.junit.InteractionRunner.run(InteractionRunner.kt:162) at au.com.dius.pact.provider.junit.PactRunner.runChild(PactRunner.kt:150) at au.com.dius.pact.provider.junit.PactRunner.runChild(PactRunner.kt:56) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.run(ParentRunner.java:363)```

anddreiu
2020-09-30 10:40
just verified now that on 4.1.1 is working fine, but when I use 4.1.2 it fails with the above error

sathisan
2020-09-30 11:19
Hello everyone, I have one question regarding Contract testing with Pact: I have Not used the pact Broker in my setup, since Consumer and provider reside in the same repository. Locally, build is successful, but after merging my pipeline fails because the pacts are not found. I am using maven as build tool and jenkins for pipeline setup. Can someone help me? How do i make Sure that consumer tests ade executed before provider tests?

wesleythomaswilliams
2020-09-30 11:21
Are your consumer and provider tests junit tests?

sathisan
2020-09-30 11:23
Yes i am using juni5

wesleythomaswilliams
2020-09-30 11:27
So one of the things we've done in our tests is to separate our unit, contract and component tests by maven profiles, so that we can execute them in different stages of our jenkins pipelines. This could be a way for you to separate your consumer and provider tests, but I'm sure there are others too.

wesleythomaswilliams
2020-09-30 11:28
```<profiles> <profile> <id>consumer-tests</id> <!-- consumer tests --> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <excludes> <exclude>**/*ConsumerTest.java</exclude> </excludes> </configuration> </plugin> </plugins> </build> </profile> <profile> <id>provider-tests</id> <!-- only provider tests --> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <includes> <include>**/*ProviderTest.java</include> </includes> </configuration> </plugin> </plugins> </build> </profile> </profiles>```

wesleythomaswilliams
2020-09-30 11:30
```mvn test -Pconsumer-tests mvn test -Pprovider-tests```

sathisan
2020-09-30 11:31
Thank you, in the section for Consumer tests, why do Dou exclude ConsumerTest.java, does it Not need to be included if the Profile is consumer-tests?

abubics
2020-09-30 11:49
Judging by the error message: > Invalid JSON (1:2), found unexpected character '<' in my experience, that usually means XML is going somewhere that expects JSON.

abubics
2020-09-30 11:50
If you can breakpoint where the exception is thrown, you might have more luck debugging :upside_down_face:

abubics
2020-09-30 11:51
Not sure why it would've changed behaviour over that version range, though :s

anddreiu
2020-09-30 11:51
yep, that's also my question

abubics
2020-09-30 11:53
Someone like @uglyog may have an answer for you tomorrow :slightly_smiling_face: it's almost 10pm here, so you might have to wait 10+ hours :pray:

anddreiu
2020-09-30 11:53
sure, no worries :slightly_smiling_face:

giuseppe.salvatore
2020-09-30 17:51
Hi guys, I was looking at the PACT contracts in the broker and for some reasons I can't see the given clause printed in the list (in fact I had to add it manually to give it more sense)

giuseppe.salvatore
2020-09-30 17:51
my code looks like this

giuseppe.salvatore
2020-09-30 17:52
```return builder .given("Average usage is not available for existing MSISDN " + mobileNumber2) .uponReceiving("A GET request to /" + mobileNumber2 + "/average-usage given average usage not available for existing MSISDN " + mobileNumber2) .method("GET") .headers(headers.toSingleValueMap()) .path("/" + mobileNumber2 + "/average-usage") .willRespondWith() .status(200) .body(bodyObject) .toPact();```

giuseppe.salvatore
2020-09-30 17:59
and this is what I get in the broker

giuseppe.salvatore
2020-09-30 17:59
which is fine as a workaround but the given should really be before

phil.endsley
2020-09-30 18:09
What version of the jvm libs and pact broker are you using? Our givens show up correctly

giuseppe.salvatore
2020-09-30 18:16
yeah I suspect is the pact version that is not understood by the broker

giuseppe.salvatore
2020-09-30 18:17
so I have got pact-jvm-consumer: 3.5.24 (I am updating it now to 4.0.10)

giuseppe.salvatore
2020-09-30 18:17
not sure how to check the broker version

giuseppe.salvatore
2020-09-30 18:17
let me see

phil.endsley
2020-09-30 18:18
If you look at the API browser in broker, it will show as a response header

giuseppe.salvatore
2020-09-30 18:21
ah sweet... it was right in front of my face

giuseppe.salvatore
2020-09-30 18:21
```x-pact-broker-version: 2.32.0```

giuseppe.salvatore
2020-09-30 18:21
bit old?

giuseppe.salvatore
2020-09-30 18:22
here is the repo I have used and it was deployed using helm


phil.endsley
2020-09-30 18:23
A bit :slightly_smiling_face:

phil.endsley
2020-09-30 18:23
I would try updating versions and seeing if that fixes it. A lot can change in a year and a half :grin:

giuseppe.salvatore
2020-09-30 18:36
that makes sense... I have just seen the example PACT that I published a while ago and that works

giuseppe.salvatore
2020-09-30 18:37
```Given there is an alligator named Mary, upon receiving a request for an alligator from Example App, with```

giuseppe.salvatore
2020-09-30 18:37
but I can see the PACT contract version is 2.0

giuseppe.salvatore
2020-09-30 18:38
```"metadata": { "pactSpecification": { "version": "2.0.0" }```

giuseppe.salvatore
2020-09-30 18:39
but yeah I will try updating it

giuseppe.salvatore
2020-09-30 18:39
thanks @phil.endsley :+1:

giuseppe.salvatore
2020-09-30 18:39
appreciated

giuseppe.salvatore
2020-09-30 18:48
do I need to redeploy with helm to update it?

giuseppe.salvatore
2020-09-30 18:49
I am worried about losing the current contracts

giuseppe.salvatore
2020-09-30 19:15
is there a way to force the pact to be at a specific version?

giuseppe.salvatore
2020-09-30 19:18
ah found it

giuseppe.salvatore
2020-09-30 19:18
in pact provider rule

phil.endsley
2020-09-30 19:18
> do I need to redeploy with helm to update it? However you want to do it. That's certainly one way of doing it though > I am worried about losing the current contracts https://docs.pact.io/pact_broker/upgrading/#pact-broker-versions--210 Might be best to ask in #pact-broker if you have any concerns around upgrading

giuseppe.salvatore
2020-09-30 19:19
:+1:

giuseppe.salvatore
2020-09-30 19:19
I was only worried as I have demo tomorrow.... after that I can wipe it all

jarmy
2020-09-30 19:33
Hi. I?m having difficulty coming up with a `PactDslJsonBody` that replicates the `containers` array in the below response for my consumer test.

jarmy
2020-09-30 19:33
```{ "sduiVersion": "1", "itemId": "8NKxTe5NVYD0LTTdT7Vd556hhrO4CYIvoO8YgcHthnjXqtTtkDV7OPKWBcDHewMNh3V5hFcEMWJ8MVTt", "wallClock": 1600732583943, "page": { "itemId": "vTmP4bTE1WFEOsuGJhfpJaYWlGBvopVVGGXITgDqeR27BFuDaq0bAgo97VBlnQhnSF5H3DvyLQ8wr0qwSNjbB4mSvOebZUkBd", "type": "CONTAINER", "view": "PAGE", "containers": [ { "itemId": "vTmP4bTE1WFEOsuGJhfpJaYWlGBvopVVGGXITgDqeVANKYkqGdGHGD4BpSpuiema4pJAEDYRCIHvGYH78zxuyG8YKNM74rPrt", "type": "CONTAINER", "component": "page-header", "items": [ { "itemId": "KNLPoAiSQztjy0hWVdlnBGJu1I81cCzQDHDaZ3YwbmtWQfkKZwON2KuRw8GAUiEdvmMuy6jp9IEtHOhEHLqsVx6Y891eRdl0dQD76RwRLBYv", "component": "title", "texts": { "title": { "value": "Today", "scheme": "LITERAL" } } } ] }, { "itemId": "3N223Jbz6ia0BmXTSUXpo1oWufmexKZ0XDHaXLTZT76s1p6q2y8aHHzgwvLYCWVOP0ErMcpri46CkWrbmFGzwZ0V3VM59pJ", "type": "CONTAINER", "component": "bottom-nav", "items": [ { "itemId": "8CUfQp10B6aDL0QX77TidM9TbTbiEefovnPelSCOOszTYtCh2PtTzGkAJRPdtsoNDlecuGZqbhLnHUR8QL1qCC72LW2qjJC32llecUsLjHqj9xnHqEOZJ2wKyHR", "type": "ITEM", "component": "bottom-nav-item", "selected": "SELECTED_1", "texts": { "title": { "value": "For You", "scheme": "LITERAL" } }, "images": { "icon": { "value": "ForYou", "scheme": "BINDING" } }, "actions": { "default": [ { "context": "displayPage", "type": "PRIMARY", "intentType": "VIEW", "intentId": "KNLPoAiSQztjy0hWVdlnBGJu1I81cCzQDHDaZ3YwdsT98XEKnB0a8Da8R26ZCJqInCQmKPKO02CEeuVGqxGqb33LG8Ggmw0iqSryvCs4iCQD" }, { "context": "selectItem", "type": "PRIMARY", "intentType": "LOCAL", "intentId": "selectItem" } ] } }, { "itemId": "TpBmBLYzEdkkezmDogEjnq1Hjs2FzIw5VZPG39E1Y8LmHh09dv5ECS1UPFMPkLrPN9gHuBaPruxy7lRjak9LXxEeQFn7lCZhjZQZNwnwqvSpg0WUUATZfICn", "type": "ITEM", "component": "bottom-nav-item", "texts": { "title": { "value": "Live", "scheme": "LITERAL" } }, "images": { "icon": { "value": "Live", "scheme": "BINDING" } }, "actions": { "default": [ { "context": "displayPage", "type": "PRIMARY", "intentType": "VIEW", "intentId": "1C6HDlEXfLYj64bVDovqL5fS8T5HcdHfDJLLdUoK7ShBQEDTBpv8bmFOYeW9Nz4nJVsP5OHoP7jsTCAdbaOv80GE1hEhDwbtOKcOlBkYPp" }, { "context": "selectItem", "type": "PRIMARY", "intentType": "LOCAL", "intentId": "selectItem" } ] } }, { "itemId": "8CUfQp10B6aDL0QX77TidM9TbTbiEefovnPelSCOOszTYtCh2PtTzGkAJRPdynJzHheHTF1rb8XBPRKMB4Mwawf7MzvpLYnUDmercFoLChCOSZqxivJjoDHzEML", "type": "ITEM", "component": "bottom-nav-item", "texts": { "title": { "value": "Search", "scheme": "LITERAL" } }, "images": { "icon": { "value": "Search", "scheme": "BINDING" } }, "actions": { "default": [ { "context": "displayPage", "type": "PRIMARY", "intentType": "VIEW", "intentId": "KNLPoAiSQztjy0hWVdlnBGJu1I81cCzQDHDaZ3YwdsT98XEKVEtpM4dCKHZHKlfMO41pQEgv6DXcmQItSiTWCDPkjgSktqV18IfNpIadaWvB" }, { "context": "selectItem", "type": "PRIMARY", "intentType": "LOCAL", "intentId": "selectItem" } ] } }, { "itemId": "Xrad4ke8jrBX4jlYjOsiIVT8EkFieVwgIe1wJwRAkl3q43wPhyv5oz8caHBlHADNbsIDenYdZ9P3G9cmxDcwFuvkOBrrGFBVjLr12elqbvGJDjxCvDxJfzPbjKQ5", "type": "ITEM", "component": "bottom-nav-item", "texts": { "title": { "value": "My Stuff", "scheme": "LITERAL" } }, "images": { "icon": { "value": "MyStuff", "scheme": "BINDING" } }, "actions": { "default": [ { "context": "displayPage", "type": "PRIMARY", "intentType": "VIEW", "intentId": "1M8OQZAFZPTa9nmtiEeDL4VOBJKr8fldcEp66ykiI8euLjFDcczChmPISl8x4mlXv4RD8N5jyEJXgQyetQjMAPO9zxd3tygJm8Mea7rnZZojpR" }, { "context": "selectItem", "type": "PRIMARY", "intentType": "LOCAL", "intentId": "selectItem" } ] } } ] } ] } }```

jarmy
2020-09-30 19:33
I?m currently using the below code but the response it?s generating is insufficient. Does anyone have a suggestion as to how to properly build this body? ``` val jsonBody = PactDslJsonBody() .stringType("sduiVersion") .stringType("itemId") .`object`("page") .stringType("itemId") .stringValue("type", "CONTAINER") .stringValue("view", "PAGE") .minArrayLike("containers", 1) .stringType("itemId") .stringValue("type", "CONTAINER") .stringType("component") .minArrayLike("items", 1) .stringType("itemId") .stringType("component") .`object`("texts") .`object`("title") .stringType("value") .stringType("scheme") .closeObject() .closeObject() .closeArray() .closeObject() .closeArray()```

giuseppe.salvatore
2020-09-30 20:02
yeah forcing version V2 for Pact Spec fixed it

giuseppe.salvatore
2020-09-30 20:02
I will update the broker next

giuseppe.salvatore
2020-09-30 20:02
thanks again Phil for your support

wesleythomaswilliams
2020-09-30 21:56
My mistake, that was a typo

uglyog
2020-09-30 22:45
The JSON parser was changed. Can you provide the pact file (prob in a Github issue)

matt.fellows
2020-09-30 22:47
more :taco: for @phil.endsley

matt.fellows
2020-09-30 22:55
thanks @wesleythomaswilliams :taco:

phil.endsley
2020-10-01 00:37
> I will update the broker next > Major upgrades the day before a demo? I see you like to live dangerously :sweat_smile:

phil.endsley
2020-10-01 00:37
Good luck with it!

anddreiu
2020-10-01 07:09
Hi @uglyog. I've just seen the problem here. I am using XML request in body and the error appears if the content type "text/xml" is not specified for the interaction request

anddreiu
2020-10-01 07:10
with the previous versions it was not mandatory to add: ``` "headers": { "Content-Type": "text/xml" }```

anddreiu
2020-10-01 07:11
I will raise a Github issue for this


aliaksandr.valadzko
2020-10-01 08:20
Hey guys! Should be popular question, however can?t find the answer I use PactDslWithProvider to generate consumer expectations of GET request Let the path will be GET api/message/{Id}/words From Provider side I use State to generate necessary message resource However from Provider side it is not known what Id of resource would be generated As path of CREATE is POST api/message So, message id is dynamic How can I deal with it? Is it possible to pass id from state to pact? Thanks in advance

aliaksandr.valadzko
2020-10-01 09:12
Found the answer It is possible to modify uri using TargetRequestFilter

matt.fellows
2020-10-01 11:10
You could use that, but it?s better to use provider states - have you come across that concept yet?

wesleythomaswilliams
2020-10-01 11:29
@jarmy this may be a typo, but you have some quotes around your object declaration for `page`. You're also missing your declaration for `wallClock` I'm just looking at the rest now.

wesleythomaswilliams
2020-10-01 11:39
I think the main problem is the last closeObject and closeArray are the wrong way around. I've written up how I'd do the whole thing, which is slightly different, as I tend to use stringType over stringValue, but you may have a specific reason for that. See if this works: ```val jsonBody = PactDslJsonBody() .stringType("sduiVersion", "1") .stringType("itemId", "8NKxTe5NVYD0LTTdT7Vd556hhrO4CYIvoO8YgcHthnjXqtTtkDV7OPKWBcDHewMNh3V5hFcEMWJ8MVTt") .integerType("wallClock", 1600732583943) .object("page") .stringType("itemId", "vTmP4bTE1WFEOsuGJhfpJaYWlGBvopVVGGXITgDqeR27BFuDaq0bAgo97VBlnQhnSF5H3DvyLQ8wr0qwSNjbB4mSvOebZUkBd") .stringType("type", "CONTAINER") .stringType("view", "PAGE") .minArrayLike("containers", 1) .stringType("itemId", "vTmP4bTE1WFEOsuGJhfpJaYWlGBvopVVGGXITgDqeVANKYkqGdGHGD4BpSpuiema4pJAEDYRCIHvGYH78zxuyG8YKNM74rPrt") .stringType("type", "CONTAINER") .stringType("component", "page-header") .minArrayLike("items", 1) .stringType("itemId", "KNLPoAiSQztjy0hWVdlnBGJu1I81cCzQDHDaZ3YwbmtWQfkKZwON2KuRw8GAUiEdvmMuy6jp9IEtHOhEHLqsVx6Y891eRdl0dQD76RwRLBYv") .stringType("component", "title") .object("texts") .object("title") .stringType("value", "Today") .stringType("scheme", "LITERAL") .closeObject() .closeObject() .closeArray() .closeArray() .closeObject()```

wesleythomaswilliams
2020-10-01 11:40
I always use example values, as I find it a good reference for myself and others when looking at the DSL.

aliaksandr.valadzko
2020-10-01 11:43
I use provider state Problem is that during creation of resource within provider state, resource will have some not known id


aliaksandr.valadzko
2020-10-01 12:04
Hey @uglyog! I saw this article, however I couldn't find any suitable solution for my case In the article it is advised to use `queryParameterFromProviderState("accountNumber", "\${accountNumber}", "100")` instead of `query("accountNumber=100")` My case: *Consumer:* ``` @Pact(consumer = "some_consumer") public RequestResponsePact pactForCreateGroup(PactDslWithProvider builder) { Map<String, String> responseHeaders = new HashMap<>(); responseHeaders.put("Content-Type", "application/json"); PactDslJsonBody pactBodyJson = new PactDslJsonBody() .stringType("id") ... .asBody(); return builder .given("message is created state") .uponReceiving("get words request") .matchPath(String.format("/api/messages/$s/words", "someIdThatINeedToCreateInProvider")) .method(HttpMethod.GET.name()) .willRespondWith() .status(HttpStatus.OK.value()) .headers(responseHeaders) .body(pactBodyJson).toPact(); }``` *Provider:* ``` private String createdInStateMessageId; @TargetRequestFilter public void changeResourceId(HttpRequestBase request) throws URISyntaxException { if (Objects.nonNull(createdInStateGroupId)) { String uri = request.getRequestLine().getUri(); if (uri.contains("someIdThatINeedToCreateInProvider")) { uri = uri.replace("someIdThatINeedToCreateInProvider", createdInStateMessageId); } request.setURI(new URI(uri)); } } @State("message is created state") public void messageExistsState() { Response<JsonObject> createMessageResponse = ... createdInStateMessageId = createMessageResponse.getMessageId(); }``` Could you please advice me how can I pass value from provider state in this case? Thanks

aliaksandr.valadzko
2020-10-01 12:26
I'm asking because `PactDslRequestWithPath` doesn't have `queryParameterFromProviderState` method (using group: 'http://au.com.dius', name: 'pact-jvm-consumer-junit_2.11', version: '3.5.24')

phil.endsley
2020-10-01 12:33
https://docs.pact.io/implementation_guides/jvm/consumer/junit#having-values-injected-from-provider-state-callbacks-3611 Looks like you'll need to upgrade the version you're using. Then in consumer: ```... .pathFromProviderState("/api/messages/${messageId}/words", "/api/messages/placeholderMessageId/words") ...``` And in provider: ``` @State("message is created state") public Map<String, Object> messageExistsState() { Response<JsonObject> createMessageResponse = ... return Map.of("messageId", createMessageResponse.getMessageId()); }```

aliaksandr.valadzko
2020-10-01 12:40
Oh, got it, thanks However it looks like I use latest version Damn, it looks like I need to change lib from `pact-jvm-consumer-junit_2.11` to `pact-jvm-consumer-junit`

phil.endsley
2020-10-01 12:43
The latest version is 4.1.7. The package names changed a while ago with 4.1.0 (I think) when the project converted to java 9 modules. https://mvnrepository.com/artifact/au.com.dius.pact.consumer/junit

phil.endsley
2020-10-01 12:44
Note there are breaking changes, but I'm pretty sure it's all just package changes. So you should only need to fix your imports when you do upgrade

aliaksandr.valadzko
2020-10-01 12:44
Thanks a lot!

aliaksandr.valadzko
2020-10-01 13:21
Everything works as expected, thanks!

antonello
2020-10-01 15:27
:taco: :taco: for @phil.endsley!

jarmy
2020-10-01 16:08
Hi Wes. I appreciate the assistance. Regarding the `.`object`("page")` , that?s the syntax IntelliJ makes me use :shrug:. I?ve deliberately left out `wallClock` because I?ve had a tough time getting it verified on the provider side with whatever I?ve tried.

jarmy
2020-10-01 16:49
In fact, if I include `wallClock`, the verification test fails with ```1.1) BodyMismatch: $ BodyMismatch: $ Expected a Map with at least 4 elements but received 3 elements``` That said, when I use your above code _without_ wallClock, the pact passes verification

jarmy
2020-10-01 16:50
Great point about using examples in the contract. I was completely ignorant of using them.

jarmy
2020-10-01 18:34
So, back to my original question. How do I construct the PactDslJsonBody to include the additional response items? Specifically, the 2nd item in the containers array.

jarmy
2020-10-01 18:34
```{ "sduiVersion": "1", "itemId": "8NKxTe5NVYD0LTTdT7Vd556hhrO4CYIvoO8YgcHthnjXqtTtkDV7OPKWBcDHewMNh3V5hFcEMWJ8MVTt", "wallClock": 1600732583943, "page": { "itemId": "vTmP4bTE1WFEOsuGJhfpJaYWlGBvopVVGGXITgDqeR27BFuDaq0bAgo97VBlnQhnSF5H3DvyLQ8wr0qwSNjbB4mSvOebZUkBd", "type": "CONTAINER", "view": "PAGE", "containers": [ { "itemId": "vTmP4bTE1WFEOsuGJhfpJaYWlGBvopVVGGXITgDqeVANKYkqGdGHGD4BpSpuiema4pJAEDYRCIHvGYH78zxuyG8YKNM74rPrt", "type": "CONTAINER", "component": "page-header", "items": [ { "itemId": "KNLPoAiSQztjy0hWVdlnBGJu1I81cCzQDHDaZ3YwbmtWQfkKZwON2KuRw8GAUiEdvmMuy6jp9IEtHOhEHLqsVx6Y891eRdl0dQD76RwRLBYv", "component": "title", "texts": { "title": { "value": "Today", "scheme": "LITERAL" } } } ] }, { "itemId": "3N223Jbz6ia0BmXTSUXpo1oWufmexKZ0XDHaXLTZT76s1p6q2y8aHHzgwvLYCWVOP0ErMcpri46CkWrbmFGzwZ0V3VM59pJ", "type": "CONTAINER", "component": "bottom-nav", "items": [ { "itemId": "8CUfQp10B6aDL0QX77TidM9TbTbiEefovnPelSCOOszTYtCh2PtTzGkAJRPdtsoNDlecuGZqbhLnHUR8QL1qCC72LW2qjJC32llecUsLjHqj9xnHqEOZJ2wKyHR", "type": "ITEM", "component": "bottom-nav-item", "selected": "SELECTED_1", "texts": { "title": { "value": "For You", "scheme": "LITERAL" } }, "images": { "icon": { "value": "ForYou", "scheme": "BINDING" } }, "actions": { "default": [ { "context": "displayPage", "type": "PRIMARY", "intentType": "VIEW", "intentId": "KNLPoAiSQztjy0hWVdlnBGJu1I81cCzQDHDaZ3YwdsT98XEKnB0a8Da8R26ZCJqInCQmKPKO02CEeuVGqxGqb33LG8Ggmw0iqSryvCs4iCQD" }, { "context": "selectItem", "type": "PRIMARY", "intentType": "LOCAL", "intentId": "selectItem" } ] } }, { "itemId": "TpBmBLYzEdkkezmDogEjnq1Hjs2FzIw5VZPG39E1Y8LmHh09dv5ECS1UPFMPkLrPN9gHuBaPruxy7lRjak9LXxEeQFn7lCZhjZQZNwnwqvSpg0WUUATZfICn", "type": "ITEM", "component": "bottom-nav-item", "texts": { "title": { "value": "Live", "scheme": "LITERAL" } }, "images": { "icon": { "value": "Live", "scheme": "BINDING" } }, "actions": { "default": [ { "context": "displayPage", "type": "PRIMARY", "intentType": "VIEW", "intentId": "1C6HDlEXfLYj64bVDovqL5fS8T5HcdHfDJLLdUoK7ShBQEDTBpv8bmFOYeW9Nz4nJVsP5OHoP7jsTCAdbaOv80GE1hEhDwbtOKcOlBkYPp" }, { "context": "selectItem", "type": "PRIMARY", "intentType": "LOCAL", "intentId": "selectItem" } ] } }, { "itemId": "8CUfQp10B6aDL0QX77TidM9TbTbiEefovnPelSCOOszTYtCh2PtTzGkAJRPdynJzHheHTF1rb8XBPRKMB4Mwawf7MzvpLYnUDmercFoLChCOSZqxivJjoDHzEML", "type": "ITEM", "component": "bottom-nav-item", "texts": { "title": { "value": "Search", "scheme": "LITERAL" } }, "images": { "icon": { "value": "Search", "scheme": "BINDING" } }, "actions": { "default": [ { "context": "displayPage", "type": "PRIMARY", "intentType": "VIEW", "intentId": "KNLPoAiSQztjy0hWVdlnBGJu1I81cCzQDHDaZ3YwdsT98XEKVEtpM4dCKHZHKlfMO41pQEgv6DXcmQItSiTWCDPkjgSktqV18IfNpIadaWvB" }, { "context": "selectItem", "type": "PRIMARY", "intentType": "LOCAL", "intentId": "selectItem" } ] } }, { "itemId": "Xrad4ke8jrBX4jlYjOsiIVT8EkFieVwgIe1wJwRAkl3q43wPhyv5oz8caHBlHADNbsIDenYdZ9P3G9cmxDcwFuvkOBrrGFBVjLr12elqbvGJDjxCvDxJfzPbjKQ5", "type": "ITEM", "component": "bottom-nav-item", "texts": { "title": { "value": "My Stuff", "scheme": "LITERAL" } }, "images": { "icon": { "value": "MyStuff", "scheme": "BINDING" } }, "actions": { "default": [ { "context": "displayPage", "type": "PRIMARY", "intentType": "VIEW", "intentId": "1M8OQZAFZPTa9nmtiEeDL4VOBJKr8fldcEp66ykiI8euLjFDcczChmPISl8x4mlXv4RD8N5jyEJXgQyetQjMAPO9zxd3tygJm8Mea7rnZZojpR" }, { "context": "selectItem", "type": "PRIMARY", "intentType": "LOCAL", "intentId": "selectItem" } ] } } ] } ] } }```

jarmy
2020-10-01 23:12
Has anyone been able to add `consumerVersionSelectors` to a Kotlin test class? https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors/ documentation says to use this code but the syntax doesn?t work. ```@PactBroker( host="pactbroker.local", port="8080", consumerVersionSelectors={ @ConsumerVersionSelector(tag = "master"), @ConsumerVersionSelector(tag = "test"), @ConsumerVersionSelector(tag = "production", latest = false) })```

uglyog
2020-10-01 23:16
Kotlin uses `[]` for arrays and you don't include the `@` on the child annotation

uglyog
2020-10-01 23:16
```@PactBroker( consumerVersionSelectors = [VersionSelector(tag = "test")] )```

jarmy
2020-10-01 23:20
Thanks!

giuseppe.salvatore
2020-10-02 10:10
@phil.endsley naaa will do it after!! I love danger but I also love to keep my job

giuseppe.salvatore
2020-10-02 10:10
:laughing:

nazar.khmil
2020-10-05 10:34
has joined #pact-jvm

xandebianchi
2020-10-05 13:05
has joined #pact-jvm

xandebianchi
2020-10-05 13:13
Hi guys! Could you help me please ? I?m starting with http://pact.io and pactflow, using Android, but it?s a generic doubt. I could create the classes and unit test, and generate the pact file. I published it using Gradle task. 1. My doubt is about the Provider. Do I need to create the provider part or this is a task for the Microservices responsibles? 2.  Also, how can I test to Verify a Pact? Where can I add the URL from Microservice for pactflow to analyze the results ? 3. For pactflow to execute correctly, do I need to put the tasks in CI ?

antonello
2020-10-05 14:20
Hi @xandebianchi, welcome! 1. From what you wrote I assume that you are involved in the development of a consumer (the Android app). Usually the developers / teams responsible for the provider would write the provider tests. However, nothing would stop you from doing it yourself, especially if you?re retrofitting tests for any pre-existing implementation. 2. Not sure I understand this question. A pact gets verified by provider tests. In what language is the provider written? 3. You can publish and retrieve from the pactflow broker even without having the tests setup in CI. If you want to adopt Pact seriously, you?d need to set up both consumer and provider tests to run on CI.

xandebianchi
2020-10-05 14:35
Ok!! thank you! If fact the second question I think I misunderstood the idea, I thought I was also responsible for testing the provider, but as a consumer and responsible only for the consumer-android part, I just need to publish contract, not test the backend response. Right?

antonello
2020-10-05 14:35
correct

xandebianchi
2020-10-05 14:35
Understood! thank you!

antonello
2020-10-05 14:36
NP

dorin.enache
2020-10-05 15:01
has joined #pact-jvm

jarmy
2020-10-05 18:47
@wesleythomaswilliams Do you have any suggestions for the above situation?

thomas.hibbard
2020-10-05 19:29
@thomas.hibbard has left the channel

matt.fellows
2020-10-06 01:18
You got it @xandebianchi!

aaron.ramirez
2020-10-06 04:22
Hi everyone, I'm looking into using pactjvm for contract testing between a couple microservices developed using Scala. I know that there is support for https://github.com/DiUS/pact-jvm/tree/4_1_7/provider/specs2. However, I'm having trouble understanding how to setup integration with a pact broker, as I'm using SBT for building these projects. How can I configure this? And the _scala-pact_ project doesn't seem viable, as the last release was in 2018. Any help would be appreciated :slightly_smiling_face:

aaron.ramirez
2020-10-06 04:26
I guess one thing I'm wondering about is if the use of a gradle or maven plugin required by pactjvm?

uglyog
2020-10-06 04:31
SBT support is only for a very old version. Your best bet is to use Maven or Gradle if you can. Specs2 support is quite rudimentary as well.

uglyog
2020-10-06 04:32
If you're able to help update it, that would be awesome because I don't use Scala so have not really supported it.

aaron.ramirez
2020-10-06 04:33
ah, bummer to hear. As changing buildtools is not really an option for these projects, or at least, it would be a very painful one. I'll take a look at the sourcecode of the deprecated SBT plugin though, to see if I can wrap my head around that

aaron.ramirez
2020-10-06 04:40
Okay, so I'll see if I can quickly get pactjvm `3.6.15` integrated with the microservices I'm working with. As that appears to be the last version with SBT support. @uglyog I took a quick look at the source for the plugin, and it doesn't appear too complicated. So it might be possible for me to help add SBT support for pactjvm 4.x

uglyog
2020-10-06 04:55
It will address the oldest open issue: https://github.com/DiUS/pact-jvm/issues/226

ledinhcuong99
2020-10-06 12:53
has joined #pact-jvm

ruth
2020-10-06 13:52
has joined #pact-jvm

giuseppe.salvatore
2020-10-06 14:15
Hi guys... is there any easy way to override the consumer version when publishing the contracts to the broker? I am able to do so in the provider with `-Dpact.provider.version=<version>` but this doesn't seem to work with `-Dpact.consumer.version=<version>` on the consumer side

giuseppe.salvatore
2020-10-06 14:15
It picks up the version from project version in pom.xml

adrianojedabenitez
2020-10-06 14:18
on the consumer side I added the parameter `--consumer-app-version` to the broker

adrianojedabenitez
2020-10-06 14:18
to specify the consumer version

giuseppe.salvatore
2020-10-06 14:18
ah you are using cli to publish... ok

giuseppe.salvatore
2020-10-06 14:19
I am using `mvn pact:publish`

giuseppe.salvatore
2020-10-06 14:20
I mean I can switch to the cli it that's the only way... but I am pretty sure there must be a way, I just haven't found it google-ing around

giuseppe.salvatore
2020-10-06 14:20
thanks @adrianojedabenitez

phil.endsley
2020-10-06 14:23
I think the property name was wrong until a recent release. We're on 4.1.6 and have to specify providerVersion. Using Gradle ```pact { publish { pactDirectory = 'proj/build/pacts' pactBrokerUrl = 'https://pactbroker.arcus.coop/' tags = [project.gitBranch] providerVersion = "${project.version}-${gitRevision}" } }```

phil.endsley
2020-10-06 14:29
_NOTE:_ The pact broker requires a version for all published pacts. The `publish` task will use the version of the project by default, but can be overwritten with the `projectVersion` property. Make sure you have set one otherwise the broker will reject the pact files.


giuseppe.salvatore
2020-10-06 14:35
Like that? `mvn pact:publish -DprojectVersion=1.2-SNAPSHOT`

giuseppe.salvatore
2020-10-06 14:36
I was looking for a way to do it not from the pom

giuseppe.salvatore
2020-10-06 14:36
to override the ci with a param

giuseppe.salvatore
2020-10-06 14:36
I can still do a search and replace in the pom but I guess it's overkilling

giuseppe.salvatore
2020-10-06 14:36
ah... that didn't work :disappointed:

phil.endsley
2020-10-06 14:39
ah...Not sure then. Might not be supported?

giuseppe.salvatore
2020-10-06 14:43
oh well... I will use `sed` to override the version number in the pom.xml, that will be picked up for sure

giuseppe.salvatore
2020-10-06 14:43
or can use the cli

antonello
2020-10-06 16:12
@giuseppe.salvatore doesn?t `-DprojectVersion=1.2-SNAPSHOT` work?

antonello
2020-10-06 16:15
it should work

antonello
2020-10-06 16:15
but if it really doesn?t there is no need to use `sed`

antonello
2020-10-06 16:19
You can just create your own custom property in your pom under `<properties>`, for example in our case it has a default value `<pact.pacticipantVersion>${project.version}-${git.commit.id.abbrev}</pact.pacticipantVersion>` Then in the configuration of pact maven plugin you can do something like ```<configuration> <projectVersion>${pact.pacticipantVersion}</projectVersion> </configuration>``` And then you can just pass `-Dpact.pacticipantVersion=your_version` to `mvn`

antonello
2020-10-06 16:28
where?s my :taco:, @matt.fellows? :smile:

giuseppe.salvatore
2020-10-06 16:33
@antonello thanks for that... yeah I am surprised as well it's not working.

giuseppe.salvatore
2020-10-06 16:34
yeah mine was a brute force approach I admit yours is more elegant

giuseppe.salvatore
2020-10-06 16:35
:upside_down_face:

phil.endsley
2020-10-06 21:12
When running provider tests, I'm getting a failed verification and am not where/how to start troubleshooting. > Published verification result of 'Failed(results=[{message=Request to provider failed with an exception, exception=java.lang.AssertionError: Unexpected end event for Pact between [consumer] (version) and [provider] - [Given] <PENDING> I get this when running verification tests with pending and wip pacts enabled with ```testCompile group: 'au.com.dius.pact.provider', name: 'spring', version: '4.1.7'``` Running without pending/wip, everything is all good

antonello
2020-10-06 21:42
Have you recently upgraded to 4.1.7?

uglyog
2020-10-06 21:52
What version of the Maven plugin are you using?

uglyog
2020-10-06 21:53
Can you provide the stack trace and debug logs?

phil.endsley
2020-10-06 22:56
I can get logs in 12ish hours :grin: First time adding pacts for the application. Didn't even think to try an older version...obvious in hindsight...

matt.fellows
2020-10-06 23:17
Eventual consistency? :stuck_out_tongue:

matt.fellows
2020-10-07 00:28
LOL yass, got a taco :stuck_out_tongue:

matt.fellows
2020-10-07 00:28
@antonello please have a :taco: for demanding a taco

dothetan.040490
2020-10-07 09:14
has joined #pact-jvm

phil.endsley
2020-10-07 17:08
Instead of pasting a bunch of stuff here, I just raised an issue with all the info. https://github.com/DiUS/pact-jvm/issues/1221

dagostino.remy
2020-10-07 23:03
has joined #pact-jvm

abhi.nandan
2020-10-08 06:38
has joined #pact-jvm

rarora
2020-10-08 11:54
has joined #pact-jvm

przemyslaw.dabrowski
2020-10-08 12:36
has joined #pact-jvm

emiliano.righi
2020-10-08 13:25
has joined #pact-jvm

phil.endsley
2020-10-08 19:59
@uglyog I talked with @wilkinsweiqiangliang about updating the jvm workshop. Since they won't be available for a couple weeks, I'm taking a swing at it. I wanted to talk about how best to tackle it...I just created a new repo and am pushing branches for each step, with the intent to merge the last one into master. I guess my question is how do you want to handle giving feedback on it, since it's a lot of steps that keep building onto each other, but won't be finished until the very end


cariaga.bh
2020-10-08 21:03
has joined #pact-jvm

phil.endsley
2020-10-08 21:25
Got to step 3, which adds consumer pacts. So any feedback on best practices/what methods you want to showcase in the workshop/anything else would be great to get now

uglyog
2020-10-08 22:15
That's awesome! I'll have a look today. @matt.fellows should also take a look.

matt.fellows
2020-10-08 22:17
Amazing!!


matt.fellows
2020-10-08 22:37
The idea is that each step has a specific learning objective

matt.fellows
2020-10-08 22:37
It covers the main use cases that most people encounter

matt.fellows
2020-10-08 22:37
if we can keeep the use case consistent (product API) and the steps the same, it will really help with teams running their own internal training programs

matt.fellows
2020-10-08 22:38
I?ve got a workshop PDF that we can eventually get online to accompany said workshop, so that teams can run training themselves

phil.endsley
2020-10-08 22:45
So something I think would be really neat is if all the projects update their workshops to be the same. Then, replace all the code blocks with a language toggle, and let people mix and match consumer/provider languages. There's one page of the docs like this already, but I think that would be really neat

phil.endsley
2020-10-08 22:46
That way, I could do a workshop with js consumer and java provider without having to jump between repos


matt.fellows
2020-10-08 23:56
yes agreed! good idea

matt.fellows
2020-10-08 23:56
If everyone uses the same process to do the workshop, that will be a lot easier!

campellcl
2020-10-09 00:06
has joined #pact-jvm

elenitsaa043
2020-10-09 10:00
has joined #pact-jvm

adriangabrieloros
2020-10-09 11:05
has joined #pact-jvm

mmotornyi.consultant
2020-10-09 11:49
In spite the fact everything is up and running I have annoying warning in gradle. Maybe somebody know what to do with that?


young
2020-10-10 01:33
Hi dear pact team, sorry to bother, please help with the minArrayLike case. Pact-JVM(latest version), I want to match a JSON request with multiple items(actually they are the same) in the array. I use the following code: ```DslPart responseBody = new PactDslJsonBody() .array("data") .object() .stringType("city") .minArrayLike("stations",1,1) .numberType("id") .stringType("name") .stringType("city") .decimalType("latitude") .decimalType("longitude") .numberType("gpsRadius") .object("photoView") .stringType("large") .stringType("small") .closeObject() .closeObject() .closeArray() .minArrayLike("scooters",1,1) .numberType("id") .stringType("qrCode") .booleanType("helmetLock") .stringType("status") .decimalType("latitude") .decimalType("longitude") .decimalType("remainingBattery") .stringType("generation") .numberType("remainingRange") .closeObject() .closeArray() .minArrayLike("geoFences",1,1) .stringType("type") .numberType("maxSpeed") .stringType("city") .minArrayLike("coordinates",1,1) .decimalType("latitude") .decimalType("longitude") .closeObject() .closeArray() .object("center") .decimalType("latitude") .decimalType("longitude") .closeObject() .closeObject() .closeArray() .closeObject();``` But the test failed with BodyMismatch: `1.1) BodyMismatch: $.data.0.geoFences.1 BodyMismatch: Expected a Map with at least 5 elements but received 4 elements` { - "city": "LMnLbaMprlzTEAA7WKKn", - "center": { - "latitude": 2697217322, - "longitude": 9562908377 - }, + "type": "NO_PARKING", + "city": "DRW", "coordinates": [ { - "latitude": 98711053, - "longitude": 1182569935 + "latitude": 30.480313917533394, + "longitude": 114.3992253676513 }, { - "latitude": 3039307861, - "longitude": 9936988536 + "latitude": 30.48007948024251, + "longitude": 114.4016283055347 + }, + { + "latitude": 30.478203961567303, + "longitude": 114.402036351591 + }, + { + "latitude": 30.47824303523717, + "longitude": 114.39927070610605 + }, + { + "latitude": 30.480313917533394, + "longitude": 114.3992253676513 } ], - "maxSpeed": 74619602, - "type": "Vz45icPKycaGImQiaC9C" + "center": { + "latitude": 30.47919300342641, + "longitude": 114.40061002625403 + } } ..........

young
2020-10-10 01:35
I think the 'minArrayLike' can ensure that each item in the list matches the provided example, but it seemed that it didn't work. And what's the error of my code? Thx.

sh.ilgam_pact
2020-10-11 16:12
has joined #pact-jvm

young
2020-10-12 04:07
Just ignore, Some of them were not same. Fixed

ranjanayush03
2020-10-12 10:57
Hello all.. actually I am trying to fetch pact from a URL via @PactUrl notation but I guess the API which I am calling needs some authorization so I was unable to find a way so as to include the headers .. Any help will be much appreciated..

antonello
2020-10-12 11:01
is the url a url to the broker?

ranjanayush03
2020-10-12 11:02
Not actually a broker

ranjanayush03
2020-10-12 11:02
But where we are storing pacts there

antonello
2020-10-12 11:06
I have a feeling this might not be possible out of the box. @uglyog might confirm, but I can?t find anything that would suggest you can. A workaround might be to have some kind of proxy that can add any authentication headers for you.

anastasiia.bielik
2020-10-12 11:13
has joined #pact-jvm

ranjanayush03
2020-10-12 12:48
Okay then for that it should be added for every providers that we have.

deepika.krishnakumar
2020-10-12 15:03
has joined #pact-jvm

deepika.krishnakumar
2020-10-12 15:11
Hi. I am using @PactBroker but I want to be able to connect to the pact broker using a http proxy

phil.endsley
2020-10-12 21:25
@uglyog @matt.fellows Finished all the steps and merged into master. There's a couple minor things I still want to do (link all the branches with each step, add the LEARNING.md like Matt linked, minor readme cleanup, stuff like that). I was going to transfer ownership to pactfoundation, but it looks like I have to have permission to create repos to transfer it. I added both of you as collaborators to my repo to see if you can do it? I'll be available in 3-4ish hours from now if I need to do something on my end

matt.fellows
2020-10-12 21:39
Awesome! I'll get onto that this morning. Might be fastest to create a new repo and get you to PR Tobit (so you get Hacktoberfest cred)

matt.fellows
2020-10-12 21:39
I'll discuss with @uglyog

uglyog
2020-10-12 22:11
@PactUrl has no option for adding headers. I assume you need the authorization header set, ot are you using other headers?

anbansal27
2020-10-12 23:02
has joined #pact-jvm

uglyog
2020-10-12 23:27
I've created https://github.com/pact-foundation/pact-workshop-jvm-spring with the hacktoberfest topic. You can create a PR there off master branch. We will still need to update all the step branches as well, which will be a bit of a pain.

phil.endsley
2020-10-12 23:34
If you create blank branches for each step, I can just pr branch to branch? Idk how else to do it/an easier way

uglyog
2020-10-12 23:35
Yeah, that will work

uglyog
2020-10-12 23:36
Do you need to do PRs for all the branches. We could just push the branches from your repo using git CLI

phil.endsley
2020-10-12 23:41
Oh, that works too as long as it will let me

phil.endsley
2020-10-12 23:41
And you're a collaborator, so worst case, you just have to do it I guess

uglyog
2020-10-12 23:43
I've created the branches

matt.fellows
2020-10-13 00:06
On the plus side, the 11 branches should get you your hacktoberfest tee (just make sure we add the appropriate label to the PR!)

ranjanayush03
2020-10-13 03:45
Yes @uglyog the authorization headers I need to set.. so in the pact url is there a method like @TestRequestHeader where we can modify the headers before replaying the requests..


uglyog
2020-10-13 03:54
Can you raise an issue on the Github project to add authentication to that annotation?

ranjanayush03
2020-10-13 03:54
Yeah sure...

ranjanayush03
2020-10-13 03:54
In the pact-jvm one..or the pact-broker one

uglyog
2020-10-13 04:03
pact-jvm

prabhakar.thippa
2020-10-13 04:58
has joined #pact-jvm

giadinhluong
2020-10-13 06:24
has joined #pact-jvm

pavank
2020-10-13 08:41
has joined #pact-jvm

stephane.meng
2020-10-13 09:06
has joined #pact-jvm

abirlal.bose
2020-10-13 09:45
has joined #pact-jvm

pavank
2020-10-13 09:53
Hi All, I am new to Pact. I want to implement contact testing using Pact JVM, can anyone help with steps to start with?

antonello
2020-10-13 10:24
Hi @pavank . Have you familiarised yourself with the documentation already? I?d recommend you start from there. Read Getting Started and Guides, and then have a look at the pact workshop for pact-jvm.

antonello
2020-10-13 10:24
Or are there any specific questions and doubts you have in mind already?

pavank
2020-10-13 10:31
Hi @antonello thanks for your response, I am referring the https://github.com/DiUS/pact-jvm which is there in the readme, but it is written using springboot and I am not aware of spring , just wanted to know is there any source where I get some PACT examples without springboot?

antonello
2020-10-13 10:38
most of what?s done in pact-jvm workshop doesn?t have much to do with SpringBoothttps://github.com/DiUS/pact-workshop-jvm

pavank
2020-10-13 11:03
awesome , thanks for your time @antonello

prabhakar.thippa
2020-10-14 04:49
I have two consumers (one REST and one Message) and both have contract with the same provider. When I run my verification on provider side for the REST contract, the message contract tries to use http target and fails. Bur if I run just the message contract verification the REST contract test fails. How should I resolve this? Should I use different provider name for each of the contract?

uglyog
2020-10-14 04:59
Yes, there is a current limitation with Pact that different types of contracts need to be associated with different named interactions. The easiest way to get around that is to suffix the provider name for the message interactions to make it distinct.

prabhakar.thippa
2020-10-14 05:12
ThankYou @uglyog

ashish_garg5
2020-10-14 09:11
Hi All, I get this error in some of my provider class. In my consumer while building the contract i haven't given any header but still i can see in my expected response. "headers": { "Content-Type": "application/json; charset=UTF-8" } So when i run my provider i get this error. java.lang.AssertionError: 0 - Expected a header 'Content-Type' but was missing 1 - expected status of 200 but was 401 2 - Expected a response type of 'application/json' but the actual type was 'text/plain' Is there any way to avoid this ? Thanks.

mamtha.3687
2020-10-14 09:16
Hi, we are trying to access the pact filename at the provider side when a specific interaction runs. We tried to implement InteractionRunner but were unable to initialise its constructor. Any thoughts or ideas?

mateusz.mrzyglod
2020-10-14 09:32
has joined #pact-jvm

antonello
2020-10-14 09:46
0 - With regard to the header, it?s probably the client in your consumer that is adding the header when making the request, even if you?re not adding it specifically in your pact consumer test.

antonello
2020-10-14 09:47
1 - 401 suggests that you are missing some form of authentication that the provider expects

antonello
2020-10-14 09:48
2 - what is the provider meant to respond with? a json boy or a text body?

ashish_garg5
2020-10-14 09:50
it expects text/plain

antonello
2020-10-14 09:51
Are you setting an Accept header in your consumer test?

ashish_garg5
2020-10-14 09:51
so is there any way i can publish expected header as text/plain so that my provider matches with the same

ashish_garg5
2020-10-14 09:51
.matchHeader("Content-Type", "text/plain") will this help

antonello
2020-10-14 09:52
content-type would be about the body of the request

antonello
2020-10-14 09:53
I think you?ll have to specify an Accept header of text/plain

ashish_garg5
2020-10-14 09:58
how m not sure

antonello
2020-10-14 09:58
in the same way as above

ashish_garg5
2020-10-14 09:58
ok let me try

ashish_garg5
2020-10-14 10:00
Access-Control-Request-Headers this u r saying to use instead of Content-Type or only Accept ?

antonello
2020-10-14 10:01
you need to set a an Accept header for that specific interaction on the pact

antonello
2020-10-14 10:01
matcHeader is not the right method anyway, because it expects a regex

ashish_garg5
2020-10-14 10:02
ohh k thanks

ashish_garg5
2020-10-14 10:02
i will try

antonello
2020-10-14 10:03
As you can see here, there is a `headers` map you can set in the request object https://github.com/DiUS/pact-jvm/tree/master/consumer/junit#using-the-base-consumerpacttest

ashish_garg5
2020-10-14 10:05
yeah i did that

ashish_garg5
2020-10-14 10:05
building now

antonello
2020-10-14 10:09
before trying to run the provider test, I?d suggest you have a look at the pact and see whether it makes sense.

ashish_garg5
2020-10-14 10:21
my response body format is coming in a string now after adding expected header

ashish_garg5
2020-10-14 10:22
it was in proper format before "body": { "oldestTimestamp": 100, "count": 100, "countsBySeverity": [ { "severity": { "raw": "string", "text": "string" }, "count": 100 }, { "severity": { "raw": "string", "text": "string" }, "count": 100 }, { "severity": { "raw": "string", "text": "string" }, "count": 100 }, { "severity": { "raw": "string", "text": "string" }, "count": 100 } ] }

ashish_garg5
2020-10-14 10:23
now it is coming like this "body": "{\"oldestTimestamp\":100,\"count\":100,\"countsBySeverity\":[{\"severity\":{\"raw\":\"string\",\"text\":\"string\"},\"count\":100},{\"severity\":{\"raw\":\"string\",\"text\":\"string\"},\"count\":100},{\"severity\":{\"raw\":\"string\",\"text\":\"string\"},\"count\":100},{\"severity\":{\"raw\":\"string\",\"text\":\"string\"},\"count\":100}]}"

cathleen.yuan
2020-10-14 11:16
has joined #pact-jvm

antonello
2020-10-14 11:26
Sorry, I?m not following - I thought you said that the provider returns text/plain

dorin.enache
2020-10-14 14:01
Hi :slightly_smiling_face:. I have a problem trying when publishing: [ERROR] Failed to execute goal au.com.dius.pact.provider:maven:4.1.0:publish (default-cli) on project transaction-api: Execution default-cli of goal au.com.dius.pact.provider:maven:4.1.0:publish failed: Plugin http://au.com.dius.pact.provi der:maven:4.1.0 or one of its dependencies could not be resolved: The following artifacts could not be resolved: io.github.microutils.kotlin-logging:kotlin-logging:jar:1.6.26, io.github.microutils.kotlin-logging:kotlin-logging-commo n:jar:1.6.26, io.github.microutils.kotlin-logging:kotlin-logging-js:jar:1.6.26: Failure to find io.github.microutils.kotlin-logging:kotlin-logging:jar:1.6.26 in https://repo.maven.apache.org/maven2 was cached in the local repository , resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

dorin.enache
2020-10-14 14:01
it seems that maven is unable to find this artifact(io.github.microutils.kotlin-logging:kotlin-logging-js:jar:1.6.26) in central repo. Do you have any idea from where to pick this?

sh.ilgam_pact
2020-10-14 14:23
Hi all! I?m using pact gradle plugin for verifying pacts against a provider. I want to configure plugin to properly trigger builds for ?contract content changed? webhook. Actually I want to do exact the same thing as described in CI/CD workshop: https://github.com/pactflow/example-provider/blob/f1c91ec/src/product/product.pact.test.js#L23-L28 . but for gradle plugin. I was able to do that by using a command line project property `pact.filter.pacturl` which is described in the https://github.com/DiUS/pact-jvm/tree/4_1_7/provider/gradle#allowing-just-the-changed-pact-specified-in-a-webhook-to-be-verified-406. But in this case https://github.com/shilgam/pact-demo-provider/blob/4da668d/Makefile#L24-L34: one - for build triggered by webhook, second - for ?normal? provider build. I would like to move this logic inside gradle task definition so that I will need single command for both builds. Is it possible?

saurabhapd
2020-10-14 15:09
Update: I finally used pact-broker-client binary to upload and its working now.

ramana.jaladurgam
2020-10-14 16:10
has joined #pact-jvm

yann.courtel
2020-10-14 16:38
has joined #pact-jvm

phil.endsley
2020-10-14 18:36
I started submitting PRs. Just did step 1 & 2 for the branches for now. Rebasing my branches so it plays nice with the initial commit. Only doing a couple at first to see if its feasible. If these go without issue, I can do the rest all at once, then do step11 -> main

alik.berezovsky
2020-10-14 18:38
has joined #pact-jvm

a.robecke
2020-10-14 19:24
has joined #pact-jvm

mikahchapman
2020-10-14 21:47
has joined #pact-jvm

uglyog
2020-10-14 22:02
Why do you need the pact filename? Is this coming from a Pact Broker or some other store? The pact files on disk are normally stored as `<consumer>-<provider>.json`.


uglyog
2020-10-14 22:04
Are you going through a proxy, or are using a local repository like Artifactory?

uglyog
2020-10-14 22:59
Once `pact.filter.pacturl` is set, it is set at the JVM level and will affect how the pacts are fetched. You will need to have two separate Gradle builds running to achieve that, one with the value set and one without.

hem_kec
2020-10-15 00:44
has joined #pact-jvm

uglyog
2020-10-15 01:04
PRs merged

sh.ilgam_pact
2020-10-15 05:44
@uglyog thank you for response! And is it possible to move this logic (I.e. running webhook build if `$PACT_URL` env var set. Otherwise running ?normal? build) inside the `build.gradle` file ? In the same way that it was shown in this example: https://github.com/pactflow/example-provider/blob/f1c91ec/src/product/product.pact.test.js#L23-L28 . Does pact gradle plugin allows to do the same thing?

abubics
2020-10-15 05:47
fyi, if you get a status of 401 back, there's probably something wrong with the request. I wouldn't bother trying to fix the content type until you get the right status code.

uglyog
2020-10-15 05:49
No, it does not. The only thing that may work is creating a Gradle task that sets the system property, then runs the build, then deletes the system property and runs it again. Or spawn two builds as seperate processes.

sh.ilgam_pact
2020-10-15 05:50
@uglyog got it. Thank you a lot!

antonello
2020-10-15 08:14
Even if someone tested with the new api both on and off, it doesn?t seem to work with pact broker 2.59

anddreiu
2020-10-15 08:25
so you think there is a mismatch between the versions of Pact Broker and pact junit library? didn't have any problems with the previous versions

antonello
2020-10-15 08:27
in short - there have been api changes in the pact broker, but it seems that pact-jvm was changed to support the new api without maintaining full backward compatibility with the old broker API

dorin.enache
2020-10-15 09:58
Aparently the maven plugin is unable to find that jar in Maven central and this is why is fails. As a solution, I have edited my settings.xml file and add a pluginRepository to point to that location and it works to find those dependencies.

dorin.enache
2020-10-15 09:59
The plugin I am referring is this one:

dorin.enache
2020-10-15 09:59
```<plugin> <groupId>au.com.dius.pact.provider</groupId> <artifactId>maven</artifactId> <version>4.1.0</version>```

dorin.enache
2020-10-15 10:01
I am running this with Maven 3.5.4 and publish of pacts to pact-broker(V2.66.0.0) is working fine. The other colleagues of mine who uses a newer version of Maven 3.6.1+ are receiving an exception running the same publish on the same code

dorin.enache
2020-10-15 10:11
[ERROR] Failed to execute goal au.com.dius.pact.provider:maven:4.1.0:publish (default-cli) on project transaction-api: Execution default-cli of goal au.com.dius.pact.provider:maven:4.1.0:publish failed: Expected a HAL+JSON response from the pact broker, but got a response with no '_links'. URL: '<http://...>, LINK: 'pb:pacticipant-version-tag' -> [Help 1]

marco.cordeiro
2020-10-15 10:54
has joined #pact-jvm

betty.he
2020-10-15 14:32
has joined #pact-jvm

rodrigocs
2020-10-15 16:19
has joined #pact-jvm

uglyog
2020-10-15 22:05
Does your broker have authentication or some proxy server in front of it? The plugin is not getting a correctly formatted response from it.

mamtha.3687
2020-10-16 01:14
Trying to fetch from a different rest service through custom pact source.

francislainy.campos
2020-10-16 08:10
Hi, in case still trying to work out a solution for this, could you please post your code with only the parts that are problematic so that's a bit easier to read, otherwise this json file is a bit too long and hard to understand what is it that is still missing.

francislainy.campos
2020-10-16 08:34
You could for example perhaps remove the repeated array items as seeing one of them only would be enough to give an idea on how to translate this file into a contract. If you can create a MVP for this it would make it a bit easer to try and help identify what the issue is. Thanks.

tamer
2020-10-16 09:08
has joined #pact-jvm

tamer
2020-10-16 09:10
hello! I have a strange behaviour I can't understand

tamer
2020-10-16 09:10
we have a lot of pact already set up in the system via our broker

tamer
2020-10-16 09:10
now I'm getting this

tamer
2020-10-16 09:10
``` Verifying a pact between payments-service and payments-scheduling-service-messaging the scheduler created a dunning request 2020-10-16 11:07:21.946 WARN 60600 --- [ Test worker] org.reflections.Reflections : given scan urls are empty. set urls in the configuration Verification Failed - No annotated methods were found for interaction 'the scheduler created a dunning request'. You need to provide a method annotated with @PactVerifyProvider("the scheduler created a dunning request") that returns the message contents. Failures: 0) the scheduler created a dunning request No annotated methods were found for interaction 'the scheduler created a dunning request'. You need to provide a method annotated with @PactVerifyProvider("the scheduler created a dunning request") that returns the message contents.```

tamer
2020-10-16 09:11
but this is my test class.. the annotated method is there

tamer
2020-10-16 09:11
````@RunWith(SpringMessagePactRunner.class) @Provider("payments-scheduling-service-messaging") @PactBroker(host = "pact-broker.....", tags = '${pactbroker.tags:master}') @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) class PaymentsSchedulingMessagingProviderPact implements PactsTrait { @Autowired private ObjectMapper objectMapper @SuppressWarnings("unused") @TestTarget public final Target target = new AmqpTarget() @PactVerifyProvider("the scheduler created a payment transaction request") String scheduledPaymentTransactionEventCreated() { def message = PaymentTransactionRequestMessage.builder() ... .build() return toJson(message, objectMapper) } @PactVerifyProvider("the scheduler created a dunning request") String scheduledDunningRequestEventCreated() { def message = DunningRequestMessage.builder() ... .build() return toJson(message, objectMapper) } }```

tamer
2020-10-16 09:11
using gradle + spock + spring runner

tamer
2020-10-16 09:11
```testImplementation "au.com.dius:pact-jvm-provider-spring_2.12:3.6.15"```

tamer
2020-10-16 09:11
any idea?

dorin.enache
2020-10-16 09:41
It doesn`t have any authentication yet, but what I don`t understand is that the same codebase build and published from my machine with maven 3.5.4 works successfully and the same codebase published from another machine with maven 3.6.1+ receives that error message. To be honest I don`t understand how the Maven version influences the publish operation.

mario.gioiosa
2020-10-16 18:57
has joined #pact-jvm

uglyog
2020-10-17 01:22
That is an old version of Pact-JVM. Try the latest instead `implementation 'au.com.dius.pact.provider:spring:4.1.7'`

uglyog
2020-10-17 01:25
Yeah, there is something odd going on there. Maybe classpath loading has changed in Maven 3.6.x, and that is impacting things.

uglyog
2020-10-17 01:26
If you can look at the dependency tree to make sure the correct versions of the JAR files are being loaded

uglyog
2020-10-17 01:26
That might help diagnose the issue.

pavank
2020-10-17 19:47
Hi All, I am trying to generate pact file in XML format just by changing application/xml, when I checked the pact file only body is in xml format and rest all content is in json format only Can anybody let me know that am I following right approach or not? This is how my createPact() looks like ```@Pact(consumer = "JunitRuleConsumer") public RequestResponsePact createPact(PactDslWithProvider builder) { Map<String, String> headers = new HashMap<String, String>(); headers.put("Content-Type", "application/xml;charset=UTF-8"); return builder .given("") .uponReceiving("Pact JVM example Pact interaction") .path("/information") .query("name=Miku") .method("GET") .willRespondWith() .headers(headers) .status(200) .body("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + "<Information>\n" + " <salary>45000</salary>\n" + " <name>Hatsune Miku</name>\n" + " <nationality>Japan</nationality>\n" + " <contact>\n" + " <Email>hatsune.miku@ariman.com</Email>\n" + " <Phone_Number>9090950</Phone_Number>\n" + " </contact>\n" + "</Information>") .toPact(); }```

matt.fellows
2020-10-17 21:30
What are you expecting to see?

matt.fellows
2020-10-17 21:31
It's still an HTTP request with XML over the wire. The pact format is JSON so it encodes the XML

pavank
2020-10-18 06:36
hi @matt.fellows thanks a lot for your response, actually I am very new to Pact and I was expecting generated pact file with .xml format. I do not know my expectation is correct or not. please correct me if I am wrong. Please let me know if below pact is correct.

matt.fellows
2020-10-18 10:26
The pact file is just the where the contract details are stored. Unless you're having issues I wouldn't be worried about. Are you having issues?

lior.baber
2020-10-19 07:33
has joined #pact-jvm

mmotornyi.consultant
2020-10-19 07:49
I can't get how to define consumerVersion for each pact in gradle script. Does anybody knows how to do that? I've set `providerVersion` in `publish` section. But I need to create pacts for few different providers with different versions. It's not supported yet ?

antonello
2020-10-19 07:58
`providerVersion` is to set the version when publishing verification results. `consumerVersion` is to set the version when publishing pacts. Are you saying that you want `consumerVersion` to be different for the same consumer depending on the provider?

mmotornyi.consultant
2020-10-19 08:06
I have IntelliJ IDEA project with contract tests. I'm planing to use this project for making pacts for 3 different providers. This three providers very similar to each other that's why there will be a lot of common code. Providers use different versions. I can specify version only once and looks like it means that all three providers will use the same version. I'd like to specify 3 different versions

mmotornyi.consultant
2020-10-19 08:07
Probably I can try to create gradle modules for different providers

mmotornyi.consultant
2020-10-19 08:28
@antonello There are no such kind of property like `consumerVersion`:

mmotornyi.consultant
2020-10-19 08:55
when I use providerVersion property it actually sets consumerVersion :smiley:

antonello
2020-10-19 09:31
Interesting, it says here: https://github.com/DiUS/pact-jvm/blob/master/provider/gradle/README.md#publishing-pact-files-to-a-pact-broker > _NOTE:_ The pact broker requires a version for all published pacts. The `pactPublish` task will use the version of the gradle project by default. You can override this with the `consumerVersion` property. Make sure you have set one otherwise the broker will reject the pact files.

mmotornyi.consultant
2020-10-19 09:33
Yeah, exactly. I've read that and tried to use `consumerVersion` but it doesn't work. Either the mistake in gradle plugin or in documentation.

antonello
2020-10-19 09:35
just to clarify - do you have 1 consumer and 3 providers?

jeffbdye
2020-10-19 17:10
has joined #pact-jvm

jace
2020-10-19 19:22
has joined #pact-jvm

uglyog
2020-10-19 22:13
What version are you using?

young
2020-10-20 02:13
Hi everyone, Could someone share the 'provider state' example(Gradle, java)? Thanks in advance!


matt.fellows
2020-10-20 02:20
does it need to be a gradle provider test?


young
2020-10-20 02:22
Thank you Matt

matt.fellows
2020-10-20 02:23
sorry I don?t have one then :stuck_out_tongue:


young
2020-10-20 02:24
Thanks. It helps a lot.

young
2020-10-20 05:35
`For each provider you can specify a state change URL to use to switch the state of the provider. This URL will receive the providerState description and all the parameters from the pact file before each interaction via a POST.` Must be a POST request?? Cannot be PUT or Delete? @matt.fellows

matt.fellows
2020-10-20 05:48
POST, is that a problem?

matt.fellows
2020-10-20 05:49
remember, this is a test specific endpoint that will receive the state as JSON. That endpoint can then do what it likes with that message

matt.fellows
2020-10-20 05:49
It can?t know to do a DELETE in advance, because it doesn?t know what the state is trying to do

matt.fellows
2020-10-20 05:49
`POST /providerstatesetuppath` - create an endpoint like this, receive the JSON blog and use the description to configure your provider

matt.fellows
2020-10-20 05:50
or, use the gradle closure to handle the state

young
2020-10-20 05:56
Thank you Matt,

tamer
2020-10-20 07:57
Thanks! I ended up doing it anyway :slightly_smiling_face:

mmotornyi.consultant
2020-10-20 07:59
Yes, I have 1 consumer (backend driven app) and three providers (3 servers). ```// https://mvnrepository.com/artifact/au.com.dius/pact-jvm-consumer-junit testImplementation "au.com.dius:pact-jvm-consumer-junit:$pactVersion" // https://mvnrepository.com/artifact/au.com.dius/pact-jvm-consumer-junit testImplementation "au.com.dius.pact.consumer:junit:4.1.7" // https://mvnrepository.com/artifact/au.com.dius/pact-jvm-consumer-java8 testImplementation "au.com.dius:pact-jvm-consumer-java8:$pactVersion"``` where pactVersion == 4.0.10

antonello
2020-10-20 08:08
And you?re saying you?d want a different consumerVersion for each pact between that consumer and the 3 providers?

mmotornyi.consultant
2020-10-20 08:17
Yes. Since mobile app is backend driven it can proceed with any response. But servers can send totally different information. And each server has kind of different API versions. As soon as server move to the next version the contract between mobile app and the server will be slightly changed. So we need to update the version of a pact. For our purposes it doesn't matter is it consumerVersion or providerVersion. We treat it as a pact version in general. I guess we can just create gradle modules and treat them as different consumers. In this case it should be possible to define version for each module separately.

uglyog
2020-10-20 08:19
From the 4.1.7 release notes: > fix: renamed providerVersion to consumerVersion in Gradle publish task

uglyog
2020-10-20 08:20
So, before 4.1.7 you need to use providerVersion, but can use both afterwards


antonello
2020-10-20 08:24
@mmotornyi.consultant You need to look here https://mvnrepository.com/artifact/au.com.dius.pact

antonello
2020-10-20 08:25
the package structure has changes in 4.1.0

antonello
2020-10-20 08:25
bear in mind that if you upgrade you?ll need to make a few changes to migrate

mmotornyi.consultant
2020-10-20 08:27
I can understand what should I change

mmotornyi.consultant
2020-10-20 08:27
What should I use instead of ```classpath "gradle.plugin.au.com.dius:pact-jvm-provider-gradle:${pactVersion}"``` ?

uglyog
2020-10-20 08:30
You can use ```plugins { id 'au.com.dius.pact' version '4.1.8' }```

uglyog
2020-10-20 08:30
Or ```classpath 'au.com.dius.pact.provider:gradle:4.1.8'```

uglyog
2020-10-20 08:31
But that will need a `repositories` section in the `buildscript`

mmotornyi.consultant
2020-10-20 08:33
Maybe you can point me to the readme file where this process described?


mmotornyi.consultant
2020-10-20 08:35
Thanks! Seems it works

antonello
2020-10-20 08:36
Great! I am still a bit confused about what you?re trying to achieve with regard to your original point. It smells a bit. But it sounds like you do have a clear idea, so that?s all that matters. :slightly_smiling_face:

mmotornyi.consultant
2020-10-20 08:38
Well, I guess my idea with only 1 consumer was wrong. Probably I need to treat app as 3 different consumers then everything should be fine.

mmotornyi.consultant
2020-10-20 08:38
Thanks a lot for your help! @antonello @uglyog

antonello
2020-10-20 08:40
If there is one consumer but the consumer needs to work with different versions or the provider, that is what versioning and tagging is for.

almaak
2020-10-20 09:35
has joined #pact-jvm

andra.moraru
2020-10-20 14:13
has joined #pact-jvm

camila.coder91
2020-10-20 17:06
has joined #pact-jvm

julzelements
2020-10-21 05:25
has joined #pact-jvm

andra.moraru
2020-10-21 06:35
Hello! I was wondering if anyone here was able to integrate the Pact Mock Server with cucumber tests. At this moment, I create some mocked data using methods annotated with "@Pact" and test the contract with unit test methods annotated with "@PactVerification", but I need to reuse the mocked data also for functional tests built with cucumber. Some links with examples would also be great and I can study further. Thank you

kapil.mathur
2020-10-21 06:40
has joined #pact-jvm



andra.moraru
2020-10-21 08:27
thanks, I will take a look

dorin.enache
2020-10-21 10:06
Actually, I was not paying enough attention to all logfile and somewhere earlier in the log before this message to be printed a connection timout between the machine that tries to do the publish and pact-broker server is thrown

dorin.enache
2020-10-21 10:08
it seems there are some conectivity problems between the server and its clients. Some machine have acquired a connection from the pool(like it is mine which works) and others get imediately a timeout

dorin.enache
2020-10-21 10:11
Publishing 'App1-App2.json' with tags 'master' ... [WARNING] Could not fetch the root HAL document org.apache.http.conn.HttpHostConnectException: Connect to pact-broker:80 failed: Connection timed out (Connection timed out) at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159)

mark.hudson
2020-10-21 10:45
has joined #pact-jvm

dianaszaharia
2020-10-21 12:38
Hey! I am currently upgrading pact jvm from 4.0.5 to 4.1.9 and am struggling with *provider state params* which don't seem to be serialized correctly anymore; e.g ```given("my custom object exists", "myObject", myObject)``` would get serialized in the pact file correctly ```"providerStates": [ { "name": "my custom object exists", "params": { "myObject": <serialized_form> } } ]``` and after migrating to 4.1.9 it gets serialized to null: ```"providerStates": [ { "name": "my custom object exists", "params": { "myObject": null } } ]``` Any ideas what could be happening? I noticed Gson was dropped in 4.1.0 in favor of custom json parser; is there a different approach for sending provider state params after this change?

antonello
2020-10-21 13:00
Is that `given` your custom code?

dianaszaharia
2020-10-21 13:18
it's a simplified example, point is that objects are not serialized in the pact file anymore; primitives seem to be working fine

viniciusribeirosp
2020-10-21 14:06
has joined #pact-jvm

antonello
2020-10-21 15:06
could you share how you?re currently using the `@State` annotation?

dianaszaharia
2020-10-21 15:22
not even reaching provider verification, this is just strictly about the pact file written after consumer tests are run

antonello
2020-10-21 15:25
ah right! of course, I was being super dumb here

antonello
2020-10-21 15:30
what type is `myObject`?

dianaszaharia
2020-10-21 15:40
it's a custom object type, but for example I can reproduce with ```given("my custom object exists", "id", UUID.randomUUID())``` this will be written to pact file as: ``` "providerStates": [ { "name": "my custom object exists", "params": { "id": null } } ]```

antonello
2020-10-21 15:43
interesting - does it work with primitives or string?

dianaszaharia
2020-10-21 15:46
yep, works with primitives or boxed primitives

antonello
2020-10-21 15:47
@uglyog would be in a better place to comment on whether it?s a desired side effect or not

antonello
2020-10-21 15:48
but I guess a workaround would be `toString`

antonello
2020-10-21 15:51
if the `UUID` is the only type you are using


dianaszaharia
2020-10-21 15:54
it's not the only type, but you do have a point; I could handle the serialization part (with jackson's ObjectMapper) and send the object already serialized as string. will give it a try

cluu
2020-10-21 17:16
has joined #pact-jvm

camila.campos
2020-10-21 21:35
has joined #pact-jvm

uglyog
2020-10-21 21:54
Can you raise an issue for that, it is a regression

dianaszaharia
2020-10-22 06:54
will do, thanks!

longlevan
2020-10-22 09:15
has joined #pact-jvm

mmotornyi.consultant
2020-10-22 10:29
Simple question. What is the difference between `stringValue` and `stringType` ?

antonello
2020-10-22 10:31
`stringValue` -> Match a string value (using string equality) `stringType` -> Will match all Strings https://github.com/DiUS/pact-jvm/tree/master/consumer#dsl-matching-methods

mmotornyi.consultant
2020-10-22 10:54
Thanks

pavank
2020-10-22 14:58
Hi All, I am trying to generate pact file for POST request but I am getting below error ```u.com.dius.pact.consumer.PactMismatchesException: The following requests were not received: method: POST path: /PartnerConnect/PC_100097/AP_PRICE/AV_1.0/OG_1 query: {} headers: {Content-Type=[Content-Type: application/xml]} matchers: MatchingRules(rules={}) generators: Generators(categories={}) body: PRESENT(<?xml version="1.0" encoding="utf-8"?> <PriceUpdate> <Item> <SKU>8907411529088</SKU> <MRP>1111</MRP> <MOP>999</MOP> <SellerShippingInfo> <DeliveryType>HD</DeliveryType> <ShippingCharges>55</ShippingCharges> </SellerShippingInfo> <SellerShippingInfo> <DeliveryType>ED</DeliveryType> <ShippingCharges>55</ShippingCharges> </SellerShippingInfo> </Item> </PriceUpdate>)```

pavank
2020-10-22 14:59
Here is my test ```public class PricePactJunitRuleXmlTest { PriceProviderService priceProviderService = new PriceProviderService(); @Rule public PactProviderRule mockProvider = new PactProviderRule("IntegraPriceProvider", this); @Pact(consumer="IntegraPriceConsumer") public RequestResponsePact createPact(PactDslWithProvider builder) { Map<String, String> headersForeReq = new HashMap<String, String>(); headersForeReq.put("Content-Type", "Content-Type: application/xml"); Map<String,String> headersForResponse = new HashMap<>(); headersForResponse.put("X-Application-Context","OCTA-BRIDGE:swagger,no-liquibase,qa5:8080"); return builder .given("") .uponReceiving("Pact JVM example Pact interaction") .path("/PartnerConnect/PC_100097/AP_PRICE/AV_1.0/OG_1") .headers(headersForeReq) .method("POST") .body("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<PriceUpdate>\n" + " <Item>\n" + " <SKU>8907411529088</SKU>\n" + " <MRP>1111</MRP>\n" + " <MOP>999</MOP>\n" + " <SellerShippingInfo>\n" + " <DeliveryType>HD</DeliveryType>\n" + " <ShippingCharges>55</ShippingCharges>\n" + " </SellerShippingInfo>\n" + " <SellerShippingInfo>\n" + " <DeliveryType>ED</DeliveryType>\n" + " <ShippingCharges>55</ShippingCharges>\n" + " </SellerShippingInfo>\n" + " </Item>\n" + "</PriceUpdate>") .willRespondWith() .status(200) .headers(headersForResponse) .body("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<PriceUpdate>\n" + " <Item>\n" + " <SELLERID>100097</SELLERID>\n" + " <PRODUCTSKU>8907411529088</PRODUCTSKU>\n" + " <PRICE>1111</PRICE>\n" + " <OFFERPRICE>999</OFFERPRICE>\n" + " <HOMEDELIVERY>55</HOMEDELIVERY>\n" + " <EXPRESSDELIVERY>55</EXPRESSDELIVERY>\n" + " <STATUS>RECORD UPDATED</STATUS>\n" + " <REASON>RECORD CORRECT</REASON>\n" + " </Item>\n" + "</PriceUpdate>\n") .toPact(); } @Test @PactVerification public void runTest() throws JAXBException { priceProviderService.setBackendURL(mockProvider.getUrl()); } }```

pavank
2020-10-22 15:00
I guess I am going wrong while doing POST call , please can anybody help

paolaagudelo10
2020-10-22 15:21
has joined #pact-jvm

antonello
2020-10-22 15:34
Not really sure what you?re doing in `runTest()` but I suspect that the problem is there. Inside that method you should call whatever method makes the API request corresponding to the interaction you?ve set up.

pavank
2020-10-22 15:58
hi @antonello thanks for your quick response and input. yes I tried with API request now I am able to generate pact file.

justin.garfield
2020-10-22 16:15
has joined #pact-jvm

guppy0356.nakira
2020-10-23 00:34
has joined #pact-jvm

matt.fellows
2020-10-23 00:42
@antonello :taco: thanks!


ercalbwar
2020-10-24 19:24
has joined #pact-jvm

ercalbwar
2020-10-24 19:53
Hi everyone! I'm a bit new to this contract testing thing and I was wondering if someone could point me at a GitHub repo with a good example of asynchronous consumer tests in Java. Thanks!

antonello
2020-10-24 21:52
Hi Alberto! Have you seen already the examples in the readmes under provider/junit and consumer/junit?

ercalbwar
2020-10-24 22:37
Just found it after you mentioned it https://github.com/DiUS/pact-jvm/blob/master/consumer/junit5/src/test/java/au/com/dius/pact/consumer/junit5/AsyncMessageTest.java. Spent a fair amount of time on https://docs.pact.io/ but didn't see a reference there.

ercalbwar
2020-10-24 22:38
Do you mind if I ask you a follow up question?

ercalbwar
2020-10-24 22:39
The tests that are given as examples are not really exercising any code. They are asserting that the messages contain what it was setup above. Is this how I am supposed to write contract tests?

ercalbwar
2020-10-24 22:40
I suppose this will generate the pact file but I was expecting it would require to integrate with the business logic in order to validate the contract

ercalbwar
2020-10-24 22:41
I might be missing something

matt.fellows
2020-10-25 05:20
There are a number of examples here, including a Kafka one for Java: https://github.com/pactflow/


matt.fellows
2020-10-25 05:23
basically, you need to pass the message the consumer expects to have to the handler

matt.fellows
2020-10-25 05:24
It?s conceptually similar to the HTTP case - you still need to make sure your code can handle the message, absolutely

ercalbwar
2020-10-25 10:58
Found it! Thanks :thumbsup:

andrewshtamburg
2020-10-25 13:04
has joined #pact-jvm



francislainy.campos
2020-10-25 14:52
Perhaps these articles may help you

siad.ardroumli
2020-10-25 18:16
has joined #pact-jvm

ercalbwar
2020-10-25 20:09
Looks good indeed! Thanks @francislainy.campos

srikanthpmailid
2020-10-26 01:02
has joined #pact-jvm

photesthesis_geospiza
2020-10-26 15:10
has joined #pact-jvm

wesleythomaswilliams
2020-10-27 15:15
Having a bit a of a crisis of confidence with my contract tests and hoping someone can help (I think my brain has gone on holiday). If my provider publishes a schema which includes an array of objects and the consumer doesn't care if there are 0, 1 or X objects in the array. Does using `.eachLike` accurately represent that contract between consumer/provider? e.g. ```.eachLike("customers", 1) .stringType("name", "Bob") .closeObject() .closeArray()``` Where the consumer could receive: ```{ customers: [ ] }``` OR ```{ customers: [ { name: "Bob" } ] }```

wesleythomaswilliams
2020-10-27 15:29
Further to the above, if the provider published something like the example below, am I right to assume `eachLike` for `customers` isn't appropriate as their `outfits` can be an empty array, so is there any alternative or does this fall under pacts "no support for specifying optional attributes"? If so, does that change if size of the `customers` array is known to be fixed. i.e. the Bob and Karen objects will always be there. ```{ customers: [ { name: "Bob" outfits: [ ] }, { name: "Karen" outfits: [ { top: "blue t-shirt", bottom: "blue jeans" }, { top: "green t-shirt", bottom: "black skirt" } ] }```

antonello
2020-10-27 16:15
Imho, the most defensive option would be to have both interactions defined in your pact.

antonello
2020-10-27 16:18
but if you know that the consumer is fine with an empty array, it might not be worth it.

antonello
2020-10-27 16:25
In the case above, I would be inclined to have a nested `eachLike` for `outfits` inside the `customers` `eachLike`

antonello
2020-10-27 16:28
as above, if you wanted to be defensive and ensure that your client is indeed happy to deserialise the empty array and that the provider doesn?t stop supporting that case, you could have both interactions.

antonello
2020-10-27 16:28
clearly, depending on how much nesting and how many permutations of similar scenarios you have, your number of interactions might explode very quickly.

antonello
2020-10-27 16:29
in which case I would generally tend to stick to the most comprehensive example.

antonello
2020-10-27 16:30
regardless of optionals

antonello
2020-10-27 16:30
and leave it to some kind of non-pact tests on the consumer side to make sure that it can cope with empty arrays, optionals missing, etc.

wesleythomaswilliams
2020-10-27 16:31
@antonello mind if I contact you via DM, I've got contract tests in place for an example like this, but it'd be great to see what you think.

antonello
2020-10-27 16:32
I don?t mind at all, but it might be useful for other people to see too. I?m also keen to hear other opinions on this btw. :slightly_smiling_face:

jackbwheatley
2020-10-27 21:02
has joined #pact-jvm

carlosalmeida.xon
2020-10-27 22:06
has joined #pact-jvm

uglyog
2020-10-27 22:06
I would have 2 tests, one with an empty array and one using `minArrayLike` to ensure that the array is populated. See https://docs.pact.io/faq/#why-is-there-no-support-for-specifying-optional-attributes for more info

yousafn
2020-10-28 02:38
has joined #pact-jvm

francislainy.campos
2020-10-28 02:58
Yeah, I think you may need states for this, otherwise when you're expecting `name` to return and it will be null pact won't know whether it's a failure or just failing under the first scenario, so it'll fail always I believe.

nasir.amin
2020-10-28 11:07
has joined #pact-jvm

jimish.shah.-nd
2020-10-28 11:26
has joined #pact-jvm

adam_figgins
2020-10-28 14:20
has joined #pact-jvm

almaak
2020-10-28 15:15
hey all, I'm trying to run the pact-jvm-server as jar in my gradle project, but I think the server requires specific scala lib version. is it possible? I'm getting 2020-10-28T16:08:38.206+0100 [ERROR] [system.err] Exception in thread "main" java.lang.NoSuchMethodError: scala.App.$init$(Lscala/App;)V I have following dependencies dependency "org.scala-lang:scala-library:2.11.7" dependency "com.github.scopt:scopt_2.10:3.0.0" dependency "io.netty:netty-all:4.1.53.Final"

wesleythomaswilliams
2020-10-28 15:27
Using `minArrayLike` like this @uglyog: ```.minArrayLike("outfits", 0, 1) .stringType("top", "blue t-shirt") .stringType("bottom", "blue jeans")```

aperdomobo
2020-10-28 15:42
has joined #pact-jvm

almaak
2020-10-28 16:03
I was able to run it. got working library combo from the distribution. dependency "au.com.dius.pact:pact-jvm-server:4.1.9" dependency "org.scala-lang:scala-library:2.12.0" dependency "com.github.scopt:scopt_2.12:3.5.0" dependency "ws.unfiltered:unfiltered-netty-server_2.12:0.9.1"

diazguerra2
2020-10-28 16:06
has joined #pact-jvm

almaak
2020-10-28 16:07
now I have a strange behaviour - the server gets started multiple times from my gradle task. has anyone else had that issue?

jarmy
2020-10-28 17:31
Hi @francislainy.campos, just saw your responses?I?ve currently implemented the following function that only creates a _portion_ of the response body using `.minArrayLike("containers", 2)` ``` @Pact(provider = "pegasus", consumer = "android-sxmp-phone") @Suppress("MaxLineLength") fun createPact(builder: PactDslWithProvider): RequestResponsePact { val jsonBody = PactDslJsonBody() .stringType("sduiVersion", "1") .stringType("itemId", "8NKxTe5NVYD0LTTdT7Vd556hhrO4CYIvoO8YgcHthnjXqtTtkDV7OPKWBcDHewMNh3V5hFcEMWJ8MVTt") .numberType("wallClock", 1600732583943) .`object`("page") .stringType( "itemId", "vTmP4bTE1WFEOsuGJhfpJaYWlGBvopVVGGXITgDqeR27BFuDaq0bAgo97VBlnQhnSF5H3DvyLQ8wr0qwSNjbB4mSvOebZUkBd" ) .stringType("type", "CONTAINER") .stringType("view", "PAGE") .minArrayLike("containers", 2) .stringType( "itemId", "vTmP4bTE1WFEOsuGJhfpJaYWlGBvopVVGGXITgDqeVANKYkqGdGHGD4BpSpuiema4pJAEDYRCIHvGYH78zxuyG8YKNM74rPrt" ) .stringType("type", "CONTAINER") .stringType("component", "page-header") .minArrayLike("items", 1) .stringType( "itemId", "KNLPoAiSQztjy0hWVdlnBGJu1I81cCzQDHDaZ3YwbmtWQfkKZwON2KuRw8GAUiEdvmMuy6jp9IEtHOhEHLqsVx6Y891eRdl0dQD76RwRLBYv" ) .stringType("component", "title") .`object`("texts") .`object`("title") .stringType("value", "Today") .closeObject() .closeObject() .closeArray() .closeArray() .closeObject() return builder .uponReceiving("v1/view request") .path("/rest/v1/view") .query("deviceUuid=acctssp137-test-deviceUUID&platform=mobile") .method("GET") .willRespondWith() .status(200) .body(jsonBody) .toPact() }```

jarmy
2020-10-28 17:31
This creates the following body in the contract ``` "body": { "itemId": "8NKxTe5NVYD0LTTdT7Vd556hhrO4CYIvoO8YgcHthnjXqtTtkDV7OPKWBcDHewMNh3V5hFcEMWJ8MVTt", "wallClock": 1600732583943, "page": { "itemId": "vTmP4bTE1WFEOsuGJhfpJaYWlGBvopVVGGXITgDqeR27BFuDaq0bAgo97VBlnQhnSF5H3DvyLQ8wr0qwSNjbB4mSvOebZUkBd", "view": "PAGE", "containers": [ { "itemId": "vTmP4bTE1WFEOsuGJhfpJaYWlGBvopVVGGXITgDqeVANKYkqGdGHGD4BpSpuiema4pJAEDYRCIHvGYH78zxuyG8YKNM74rPrt", "component": "page-header", "type": "CONTAINER", "items": [ { "itemId": "KNLPoAiSQztjy0hWVdlnBGJu1I81cCzQDHDaZ3YwbmtWQfkKZwON2KuRw8GAUiEdvmMuy6jp9IEtHOhEHLqsVx6Y891eRdl0dQD76RwRLBYv", "component": "title", "texts": { "title": { "value": "Today" } } } ] }, { "itemId": "vTmP4bTE1WFEOsuGJhfpJaYWlGBvopVVGGXITgDqeVANKYkqGdGHGD4BpSpuiema4pJAEDYRCIHvGYH78zxuyG8YKNM74rPrt", "component": "page-header", "type": "CONTAINER", "items": [ { "itemId": "KNLPoAiSQztjy0hWVdlnBGJu1I81cCzQDHDaZ3YwbmtWQfkKZwON2KuRw8GAUiEdvmMuy6jp9IEtHOhEHLqsVx6Y891eRdl0dQD76RwRLBYv", "component": "title", "texts": { "title": { "value": "Today" } } } ] } ],```

jarmy
2020-10-28 17:36
If you compare it against the response I posted https://pact-foundation.slack.com/archives/C9UN99H24/p1601577250078800?thread_ts=1601494424.046900&cid=C9UN99H24, you?ll see it?s missing a number of `items` in the `containers` array. I?m not sure if it even matters?

xsamore
2020-10-28 19:52
has joined #pact-jvm

simon
2020-10-28 20:49
has joined #pact-jvm

antonello
2020-10-28 22:06
I always assumed that `eachLike` would fail if the array wasn?t populated.

uglyog
2020-10-28 22:43
It should be `.minArrayLike("outfits", 1)`

uglyog
2020-10-28 22:44
That will check the array has at least 1 item. `eachLike` only checks that each item in the array matches, it doesn't check the array length.

uglyog
2020-10-28 22:51
There is an application bundle for that that will be better to use because it has all the correct dependencies.

antonello
2020-10-28 22:58
But with `eachLike` there would have to be at least one item in the array, or otherwise it won?t match, correct?

wesleythomaswilliams
2020-10-28 23:00
@uglyog If I know that the provider will always create a message with the `customers` array exactly as presented above, with those two entries. How would you represent the array in the dsl?

uglyog
2020-10-28 23:10
@antonello `eachLike` will not generate any mismatches if there is nothing to match

uglyog
2020-10-28 23:11
@wesleythomaswilliams if they are always exactly like that, you can just use a normal array and it will check equality.

ruben.cagnie
2020-10-29 01:24
has joined #pact-jvm

ruben.cagnie
2020-10-29 01:29
Hi. We are exploring Pact at our company. So far, we've been able to set most of it up, but when we run the pact provider tests and we have a failure, the tests are marked as "skipped" (this is the output: `Pact between XXX (dev) and YYY - Upon a GET request to ... SKIPPED`). Is there a way to mark these as failed? Or is this part of the "Pending pacts" workflow?

matt.fellows
2020-10-29 01:34
The whole point of pending pacts is to _not_ fail the provider, but still send the failure results back to the broker so that the consumer will get the feedback (e.g. for can-i-deploy checks)

matt.fellows
2020-10-29 01:34
if you want to fail the provider, disable pending pacts

uglyog
2020-10-29 01:40
@ruben.cagnie how are you running the tests? The only way I know of getting skipped tests is there is no matching pacts that are fetched from the Pact Broker and you have added the `@IgnoreNoPactsToVerify` annotation to the test.

uglyog
2020-10-29 01:41
But then you would not get that output. Do you have normal `@Ignore` annotations on your tests?

matt.fellows
2020-10-29 01:41
Ah cool, I was wondering if the SKIPPED was a pact jvm specific artifact. The answer seems to be no (which is good, because that would be misleading)

uglyog
2020-10-29 01:42
I think the pending ones have `[PENDING] `

matt.fellows
2020-10-29 01:42
Could you share your provider verification code Ruben?

matt.fellows
2020-10-29 01:42
makes sense Ron

phil.endsley
2020-10-29 01:43
Might be mistaken, but I thought pending tests that failed showed the same as if you had @Ignore. To keep the build passing

ruben.cagnie
2020-10-29 01:44
So these test run fine normally, but I'm testing the scenario where we do a breaking change on the Provider side. After that, the test that fails (so the test actually did the work) gets the following message at the end: ```- Not all of the 2 were verified. The following were missing: - a GET request to get *** detail```

ruben.cagnie
2020-10-29 01:45
The test has ran, but failed: ```Failures: 1) a GET request to get *** summaries 1.1) BodyMismatch: $ BodyMismatch: Expected totalCount=2 but was missing { - "totalCount": 2, + "totalCountttt": 61,```

uglyog
2020-10-29 01:45
@phil.endsley you might be right. It triggers `notifier.fireTestIgnored(description)` for JUnit 4

ruben.cagnie
2020-10-29 01:46
What is the verification code? We are running our own pact broker, FWIW

matt.fellows
2020-10-29 01:48
the code you are using to verify the pacts on your provider side. e.g. your Pact Unit test or your gradle task settings

matt.fellows
2020-10-29 01:48
> We are running our own pact broker, FWIW we?ll forgive you :stuck_out_tongue:

uglyog
2020-10-29 01:49
@ruben.cagnie if it is due to pending pacts, there should be a notice in the standard output of the test as to why it is pending. You may need to look at the test report to see that.

ruben.cagnie
2020-10-29 01:52
sorry, I thought you were looking for a "verification code"... My bad, it's been a long day

ruben.cagnie
2020-10-29 01:53
Yeah, I'll anonymize it a bit

ruben.cagnie
2020-10-29 01:53
It's basically this: ```@RunWith(PactRunner::class) @PactBroker @Provider("ec-api") class PactContractIT { @TestTarget // Annotation denotes Target that will be used for tests val target: HttpTarget = HttpTarget(port, host, protocol) @TargetRequestFilter fun update(request: HttpRequest) { request.addHeader(ThreadLocalRequestMap.AUTHORIZATION_HEADER, generateJwt(scopes)) request.addHeader(Headers.CUSTOMER_UUID, defaultCustomerUuid) } @State("createFixtures") fun createFixtures() { FixtureFactory.createFixtures("root", "dev", "localhost") } }```

ruben.cagnie
2020-10-29 01:53
ok, will take a look

ruben.cagnie
2020-10-29 01:55
and I am using JUnit4

ruben.cagnie
2020-10-29 01:57
This is the output in standard out (I trimmed a bit) ```INFO 2020-10-29T01:54:45.253Z ec-api<unknown> "Test worker" [] a.c.d.p.p.DefaultVerificationReporter - Published verification result of 'Failed(results=[{message=Request to provider failed with an exception, exception=java.lang.AssertionError: Failures: 1) a GET request to get XXX summaries 1.1) BodyMismatch: $ BodyMismatch: Expected totalCount=2 but was missing ... PactContractIT > com.http.PactContractIT > app-bff - Upon a GET request to get XXX detail PASSED PactContractIT > com.http.PactContractIT > app-bff - Upon a GET request to get XXX summaries SKIPPED```

matt.fellows
2020-10-29 02:02
huh, have you enabled other system properties as well? Looks pretty basic

ruben.cagnie
2020-10-29 02:10
So I just tried with JUnit5 and this is behaving as expected

uglyog
2020-10-29 02:18
In the output higher up, there should be a notice section, just after where it shows what Pact URL it is running with

ruben.cagnie
2020-10-29 02:22
It is pretty basic. It just has some configs to set the broker url and some minor things

ruben.cagnie
2020-10-29 02:24
It seems like moving to JUnit5 it has the correct behavior

272939217
2020-10-29 05:33
has joined #pact-jvm

almaak
2020-10-29 08:28
thank you for taking the time! yes I've considered that but it has a lot of dependencies that we don't want to have in our repo and we still want to run the server through our gradle. is there a single jar, perhaps, that I can add to our build dependencies?

uglyog
2020-10-29 08:36
The jar you've added is the one

almaak
2020-10-29 08:53
hm, I've executed the main class http://au.com.dius.pact.server.Server with the java exec and it failed because all the other dependencies - scala, netty etc.

uglyog
2020-10-29 08:54
Yes, you will have to provide the correct dependencies.

uglyog
2020-10-29 08:55
Gradle can do it using the maven POM for it, but you will have to provide the correct classpath to the java exec

driloni92
2020-10-29 09:05
has joined #pact-jvm

almaak
2020-10-29 09:13
ok, thank you! I've tried that. and so far I've seen some of the libraries on the classpath. I'm missing the ws.unfiltered:unfiltered-netty-server_2.12 and the scopt for example, but it could be that there are hidden somewhere within other libs. :slightly_smiling_face: Unfortunately I can't run it at the moment, because I have a huge classpath and am getting an exception because of that. :face_with_rolling_eyes:

antonello
2020-10-29 11:02
@uglyog When would one want to use `eachLike` then?

pauloavra
2020-10-29 12:33
has joined #pact-jvm

ruben.cagnie
2020-10-29 12:45
Are there any examples of `pactPublish` using gradle with Kotlin DSL? I found an issue (https://github.com/DiUS/pact-jvm/issues/852) and a resolution, but I can't seem to find any examples

wesleythomaswilliams
2020-10-29 12:47
I'm curious now too on why someone would choose `eachLike` over `minArrayLike`

antonello
2020-10-29 12:48
we will have to go and change all our usages of `eachLike` to `minArrayLike`

ruben.cagnie
2020-10-29 13:13
I tried the following: ```pact.publish.pactDirectory = File(projectDir, "pacts") pact.publish.pactBrokerUrl = "http://localhost:8080" tasks.withType<Test>().configureEach { systemProperty("pact.rootDir", "./pacts") systemProperty("pact.writer.overwrite", "true") finalizedBy("pactPublish") }```

ruben.cagnie
2020-10-29 13:13
But get `Unresolved reference: pact`

almaak
2020-10-29 13:44
hm, which pom do you mean, in the pom in the pact-jvm-server there was only the library and no dependencies? <dependency> <groupId>http://au.com.dius.pact</groupId> <artifactId>pact-jvm-server</artifactId> <version>4.1.9</version> <type>pom</type> </dependency>

almaak
2020-10-29 13:50
I'm doing dependencies { runtimeClasspath(group: 'http://au.com.dius.pact', name: 'pact-jvm-server', version: '4.1.9') and not getting additional libs.

ruben.cagnie
2020-10-29 13:56
I found the solution. If anyone is interested: ```apply(plugin = "au.com.dius.pact") configure<au.com.dius.pact.provider.gradle.PactPluginExtension> { publish { pactDirectory = File(rootDir, "pacts") // defaults to $buildDir/pacts pactBrokerUrl = "http://localhost:8080" } } tasks.withType<Test>().configureEach { systemProperty("pact.rootDir", "./pacts") systemProperty("pact.writer.overwrite", "true") finalizedBy("pactPublish") }```

francislainy.campos
2020-10-29 16:46
Thank you Jason. Please don't get me wrong but I wonder whether I may have myself clear enough on the asking. The point is that this is still quite bit and hard to read and some of the things don't see to be part of the issue and could probably be removed so that the file is made a little bit smaller.

francislainy.campos
2020-10-29 16:47
It's not necessarily exactly about the sizing but it's hard to follow what the question is. Is the issue that you can't see the array of contents? Just some items inside it are missing, are the other items generating? If all of them are fine but one or two you could perhaps remove most of the ones who are alright and leave just one or two for the sake of comparison.

francislainy.campos
2020-10-29 16:48
Even the data inside the sample could also be made smaller.

francislainy.campos
2020-10-29 16:48
``` "items": [ { "itemId": "KNLPoAiSQztjy0hWVdlnBGJu1I81cCzQDHDaZ3YwbmtWQfkKZwON2KuRw8GAUiEdvmMuy6jp9IEtHOhEHLqsVx6Y891eRdl0dQD76RwRLBYv", "component": "title", "texts": { "title": { "value": "Today" } } }```

jarmy
2020-10-29 16:48
Ok, let me see if I can simplify things a bit. I?ll have something for you in the morning for you

francislainy.campos
2020-10-29 16:48
This here for example could be typed as ``` "items": [ { "itemId": "myid", "component": "title", "texts": { "title": { "value": "Today" } } }```

francislainy.campos
2020-10-29 16:49
As whether the id has 100 characters or only 4 it won't affect the outcome.


francislainy.campos
2020-10-29 16:50
This is called to produce a MVP (minimum viable product) which would be the smaller piece of code where the issue is still reproductible.

francislainy.campos
2020-10-29 16:51
And also the principal of divide and conquer, where by making a problem smaller it can get it easier to find the solution for it.

francislainy.campos
2020-10-29 16:52
I many times ended up finding the solutions for issues this way myself as may be able to figure where the issue is coming from more precisely.

francislainy.campos
2020-10-29 16:53
``` @Pact(provider = "pegasus", consumer = "android-sxmp-phone") @Suppress("MaxLineLength") fun createPact(builder: PactDslWithProvider): RequestResponsePact { val jsonBody = PactDslJsonBody() .stringType("sduiVersion", "1")```

francislainy.campos
2020-10-29 16:53
Here for example, on top of the file, we don't need to see the @Suppress annotation so you can delete that.

francislainy.campos
2020-10-29 16:54
So you can delete that

francislainy.campos
2020-10-29 16:57
``` @Pact(provider = "pegasus", consumer = "android-sxmp-phone") fun createPact(builder: PactDslWithProvider): RequestResponsePact { val jsonBody = PactDslJsonBody() .stringType("sduiVersion", "1") .stringType("itemId", "8") .numberType("wallClock", 1600732583943) .`object`("page") .stringType("itemId","v") .stringType("type", "CONTAINER") .stringType("view", "PAGE") .minArrayLike("containers", 2) .stringType("itemId","vT) .stringType("type", "CONTAINER") .stringType("component", "page-header") .minArrayLike("items", 1) .stringType("itemId","2") .stringType("component", "title") .`object`("texts") .`object`("title") .stringType("value", "Today") .closeObject() .closeObject() .closeArray() .closeArray() .closeObject() return builder .uponReceiving("v1/view request") .path("/rest/v1/view") .query("deviceUuid=acctsdeviceUUID") .method("GET") .willRespondWith() .status(200) .body(jsonBody) .toPact() }```

francislainy.campos
2020-10-29 16:58
Here, just by simplifying the ids would you agree that this becomes a bit easier to read?

francislainy.campos
2020-10-29 16:58
And let's suppose your question is just about the containers array you can simplify this even more.

francislainy.campos
2020-10-29 17:00
```@Pact(provider = "pegasus", consumer = "android-sxmp-phone") fun createPact(builder: PactDslWithProvider): RequestResponsePact { val jsonBody = PactDslJsonBody() .stringType("sduiVersion", "1") .`object`("page") .stringType("view", "PAGE") .minArrayLike("containers", 2) .stringType("itemId","vT) .minArrayLike("items", 1) .stringType("component", "title") .`object`("texts") .`object`("title") .stringType("value", "Today") .closeObject() .closeObject() .closeArray() .closeArray() .closeObject() return builder .uponReceiving("v1/view request") .path("/rest/v1/view") .query("deviceUuid=acctsdeviceUUID") .method("GET") .willRespondWith() .status(200) .body(jsonBody) .toPact() }```

francislainy.campos
2020-10-29 17:00
~And fixing the indentation~

francislainy.campos
2020-10-29 17:02
It could become even smaller but I'm not sure I understand the question but I think you get the idea and may be able to rephrase what you're trying to ask.

jarmy
2020-10-29 21:38
Ok @francislainy.campos here goes?

jarmy
2020-10-29 21:45
Here?s the simplified json response I?m trying to re-create ```{ "page": { "itemId": "1", "type": "CONTAINER", "view": "PAGE", "containers": [ { "itemId": "2", "type": "CONTAINER", "component": "page-header", "items": [ { "itemId": "2a", "component": "title", "texts": { "title": { "value": "Today", "scheme": "LITERAL" } } } ] }, { "itemId": "3", "type": "CONTAINER", "component": "bottom-nav", "items": [ { "itemId": "3a", "type": "ITEM", "component": "bottom-nav-item", "selected": "SELECTED_1", "texts": { "title": { "value": "For You", "scheme": "LITERAL" } }, "images": { "icon": { "value": "ForYou", "scheme": "BINDING" } }, }, { "itemId": "3b", "type": "ITEM", "component": "bottom-nav-item", "texts": { "title": { "value": "Live", "scheme": "LITERAL" } }, "images": { "icon": { "value": "Live", "scheme": "BINDING" } }, }, ] } ] } }``` As you can see, there are 2 `CONTAINER` types within the `containers` array with different bodies.

jarmy
2020-10-29 21:46
My question is how do I replicate the different CONTAINER types?

jarmy
2020-10-29 21:48
Here?s the current code I?m using ``` val jsonBody = PactDslJsonBody() .`object`("page") .stringType( "itemId", "1" ) .stringType("type", "CONTAINER") .stringType("view", "PAGE") .minArrayLike("containers", 2) .stringType( "itemId", "2" ) .stringType("type", "CONTAINER") .stringType("component", "page-header") .minArrayLike("items", 1) .stringType( "itemId", "2a" ) .stringType("component", "title") .`object`("texts") .`object`("title") .stringType("value", "Today") .closeObject() .closeObject() .closeArray() .closeArray() .closeObject()```

jarmy
2020-10-29 21:50
I think the problem is I can?t quite use `.minArrayLike("containers", 2)` since the containers are different

uglyog
2020-10-29 22:10
Hmm, I would have expected it to have all it's deps in there

uglyog
2020-10-29 22:12
Can you raise an issue for that on the Github project?

uglyog
2020-10-29 22:14
It's one of those things that happened and when you look back, you think: well, that is stupid

uglyog
2020-10-29 22:15
But I think that making the min rule explicit with `minArrayLike` is than better than being implicit.

antonello
2020-10-29 22:31
Understood. Would it make sense to deprecate `eachLike?`

francislainy.campos
2020-10-30 00:54
Much better!! Well done. Thanks.

francislainy.campos
2020-10-30 00:55
```val jsonBody = PactDslJsonBody() .`object`("page") .stringType("itemId","1") .stringType("type", "CONTAINER") .stringType("view", "PAGE") .minArrayLike("containers", 2) .stringType("itemId","2") .stringType("type", "CONTAINER") .stringType("component", "page-header") .minArrayLike("items", 1) .stringType("itemId","2a" ) .stringType("component", "title") .`object`("texts") .`object`("title") .stringType("value", "Today") .closeObject() .closeObject() .closeArray() .closeArray() .closeObject()```

francislainy.campos
2020-10-30 01:02
```{ "page": { "itemId": "1", "type": "CONTAINER", "view": "PAGE", "containers": [ { "itemId": "2", "type": "CONTAINER", "component": "page-header", "items": [ { "itemId": "2a", "component": "title", "texts": { "title": { "value": "Today", } } } ] }, { "itemId": "3", "type": "CONTAINER", "component": "bottom-nav", "items": [ { "itemId": "3a", "type": "ITEM", "component": "bottom-nav-item", "selected": "SELECTED_1", "texts": { "title": { "value": "For You", } }, "images": { "icon": { "value": "ForYou", } }, }, { "itemId": "3b", "type": "ITEM", "component": "bottom-nav-item", "texts": { "title": { "value": "Live", } }, "images": { "icon": { "value": "Live", } }, }, ] } ] } }```

francislainy.campos
2020-10-30 01:03
Just formatting and removing a bit more but I think I understand the question now. One of your containers have the images object whereas the other doesn't, yes?

francislainy.campos
2020-10-30 01:08
Assuming you have control on how to generate this data, you may want to use an api call where each and every item display that image object and create a contract for that situation. The verification for this contract would fail if the image is not there, but as long you use always the same params on your api and it always contains this param there, this shouldn't be much of an issue.

francislainy.campos
2020-10-30 01:17
But, if the structure is that your page-header never has the images icon but it's there only for the bottom-nav component (for each every and each item inside the bottom-nav component) and your call is always structured this way, it should be possible to include both on your contract.

francislainy.campos
2020-10-30 01:18
If you can please tell me what is the case here, I can detail this a bit more. Thank you.

uglyog
2020-10-30 03:11
Possibly, or at least update the javadoc comments and docs

almaak
2020-10-30 08:25
yes, right away.

jikogay728
2020-10-30 17:20
has joined #pact-jvm

jarmy
2020-10-30 17:32
I feel like we?re getting somewhere? In this case, the consumer doesn?t have control over the containers that are returned from the provider. The `page-header` component does _not_ have `images` and `actions` elements, but `bottom-nav-item` components do.

francislainy.campos
2020-10-30 17:42
Okay, just to be clear, by control what I mean is are you able to trigger a request that you know for sure how it's going to return back to you and that it wouldn't change too much. E.g. with some user or params you know you going to receive on page header and two bottom navs items, all of them with images, etc.

francislainy.campos
2020-10-30 17:43
If that's not the case, pact may not be the best solution to test this api..

jarmy
2020-10-30 17:48
This API is a Server Driven UI. Basically, the server controls the responses sent back to the clients by a page definition. If the provider changes the page definition, then the response can be different

francislainy.campos
2020-10-30 18:23
But when you trigger this api with some given params let's say on Postman, do you know what you're going to receive back?

francislainy.campos
2020-10-30 18:24
And if you trigger it again either immediately or after some time is that still the same?

jarmy
2020-10-30 18:25
Yes, it stays the same. I?ve had the contract in its current form running for about a month

francislainy.campos
2020-10-30 18:26
Okay, good

francislainy.campos
2020-10-30 18:26
So we can use pact for that

jarmy
2020-10-30 18:28
I sure hope so :slightly_smiling_face:. I?ve invested a lot of time into getting pact set up on 2 consumers with this provider already and I?m about to do another

francislainy.campos
2020-10-30 18:30
I'll draft something for you based on the mvp sample that we have

francislainy.campos
2020-10-30 18:39
```DslPart bodyReceived = new PactDslJsonBody() .object("page") .stringType("itemId", "1") .stringType("view", "PAGE") .eachLike("containers") .stringType("itemId", "2") .stringType("type", "CONTAINER") .stringType("component", "page-header") .eachLike("items") .stringType("itemId", "2a") .stringType("component", "title") .object("texts") .object("title") .stringType("value", "today") .closeObject() .closeObject() .closeArray() .closeArray() .closeObject();```

francislainy.campos
2020-10-30 18:40
Something like this..

francislainy.campos
2020-10-30 18:44
However, as the page-header and bottom-nav components both have the same keys (itemId, type, component, etc), I don't think we can include the images piece inside this unless we can have it also coming back for the page-header component or if you can perhaps get your backend to give you two different structures, maybe one object for page-header and another one for page-component. Otherwise, if we include the images on the array container when we're saying the each item (eachlike) should have that, then when it finds the page-header without it it will understand it as a failure.

francislainy.campos
2020-10-30 18:46
So the option I see here if this change is not possible and you're not able to have all the items come back with exact the same keys is that you may include on your contract only the keys that repeat for all items, so that you're at least asserting for them (some testing better than no testing).

jarmy
2020-10-30 20:55
that?s essentially that same idea I ended up with with the jvm test since we can?t guarantee that all the keys are the same

deepika.krishnakumar
2020-10-30 22:35
Hi. Pasting my question again. Is there a way to set http proxy before accessing a pact broker like pactflow from my provider. I?m trying from a java application. Any way of setting http.proxy. I was able to set it and publish to pactflow but the provider is unable to connect to it to read the pacts

matt.fellows
2020-10-30 22:46
If there is a standard answer we should add to the docs. I searched for proxy in Pact JVM to no avail

almaak
2020-10-31 11:23
not excatly right away, but still :slightly_smiling_face: https://github.com/pact-foundation/pact-jvm/issues/1239

blmlcu
2020-10-31 14:51
has joined #pact-jvm

uglyog
2020-10-31 23:42
You can use the standard proxy JVM system properties ```http.proxyHost http.proxyPort https.proxyHost https.proxyPort http.nonProxyHosts```

samuel.hodgkinson
2020-11-02 12:07
Hi. I'm using the groovy implementation for my Consumer, and I've set the spec version to 2.0, but it is still generating v3 matchers and features, which then breaks verification on the Provider side, as it's a golang provider, which only supports V2. Is this expected behaviour? Personally, I'd expected the Consumer code to throw an error if I set it to V2 and then tried using v3 matchers

aliaksandr.valadzko
2020-11-02 13:26
Hey guys! Could anyone help me please How can I specify `pact consumer version` when publishing to Broker? I used `tag`, however `tag` can not be used in _canIDeploy_ task - it requires `version`

aliaksandr.valadzko
2020-11-02 13:27
I use _gradle_ task `PactPublishTask` And then `PactCanIDeployTask`

aliaksandr.valadzko
2020-11-02 14:07
Found it - `providerVersion`

aliaksandr.valadzko
2020-11-02 14:08
I was a bit confused, as *consumer* version is called `providerVersion`

phil.endsley
2020-11-02 14:09
FYI - It was corrected to consumerVersion in a recent release

aliaksandr.valadzko
2020-11-02 14:09
Oh, cool, thanks

phil.endsley
2020-11-02 14:09
But yes, I've ran into this same issue

jamescourtoy
2020-11-02 21:04
has joined #pact-jvm

uglyog
2020-11-02 23:23
@matt.fellows I think we discussed this for V4

matt.fellows
2020-11-02 23:24
Yeah, I?ve added that to the (wip) golang provider. It won?t let you add matchers from a different spec

telmo.ferreira.costa
2020-11-03 11:32
has joined #pact-jvm

samuel.hodgkinson
2020-11-03 11:36
Ah sorry maybe I wasn't clear. My issue is that pact-jvm (using the groovy dsl) let's me use matchers from a different spec, not the go side

sergii.kopovskyi
2020-11-03 12:35
has joined #pact-jvm

samuel.hodgkinson
2020-11-03 13:28
So I set it to V2 on the groovy side, and it generated a pact which still had V3 matchers, without giving me an error

silverton.gimenes
2020-11-03 17:58
has joined #pact-jvm

colber16
2020-11-03 18:34
has joined #pact-jvm

cvoong
2020-11-03 18:55
has joined #pact-jvm

uglyog
2020-11-03 21:56
We understand this is an issue for you, what we are going to do moving forward is to make sure you get an error for future changes.

matt.fellows
2020-11-03 23:02
Sorry for the confusion Sam. Ron was including me in as we had recently discussed this whilst I was upgrading Golang. More of an ?FYI? to me than addressing your question

ashish_garg5
2020-11-04 06:02
Hi All, How do i run my provider against all consumer tags present in the pact broker ? I have consumer with 2 tags in broker and my provider is running against the latest one only and not the both. How i can make it to run and verify against all tags of consumer. Thanks in advance.

uglyog
2020-11-04 06:11
You need to provide the tags to use. How are you verifying your pacts?

ashish_garg5
2020-11-04 06:13
mvn clean install -Dpact.verifier.publishResults=true -Dpact.provider.version=0.0.0 -Dpact.provider.tag=test -Dpact.broker.host=<http://ciqpactdev.cec.lab.emc.com|<>host> -Dpact.broker.port=<port>

ashish_garg5
2020-11-04 06:14
this command i am using how to provide consumer tag in this ?


uglyog
2020-11-04 06:19
> pact.consumer.tags Overrides the tags used when publishing pacts [version 4.0.7+]


ashish_garg5
2020-11-04 06:20
ok thanks let me check

ashish_garg5
2020-11-04 06:21
i am using version 4.0.2 will both these doesn't work with this version ?

uglyog
2020-11-04 06:23
Probably better to upgrade to the latest

ashish_garg5
2020-11-04 06:23
ok thanks

ashish_garg5
2020-11-04 06:44
hi

ashish_garg5
2020-11-04 06:44
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <systemPropertyVariables> <pact.provider.version>${project.version}</pact.provider.version> <pact.verifier.publishResults>${pact.verifier.publishResults}</pact.verifier.publishResults> <pact.provider.tag>${pact.provider.tag}</pact.provider.tag> <pact.consumer.tags>${pact.consumer.tags}</pact.consumer.tags> </systemPropertyVariables> </configuration> </plugin>

ashish_garg5
2020-11-04 06:45
i have added pact.consumer.tags also in this plugin but it is still not working

giuseppe.salvatore
2020-11-04 20:09
Hi everyone quick question... in the consumer (jvm with maven) do I need the provider plugin to publish the contracts to the broker? Do I have any other options?

giuseppe.salvatore
2020-11-04 20:10
I am asking because I have seen this dependency and was wondering if it's doable in another way other than running `mvn pact:publish`

giuseppe.salvatore
2020-11-04 20:10
```<dependency> <groupId>au.com.dius.pact</groupId> <artifactId>pact-publish</artifactId> <version>4.1.9</version> </dependency>```

matt.fellows
2020-11-04 20:38
I'd use the CLI tools


matt.fellows
2020-11-04 20:39
You could use curl or really any API client, but the CLI is the simplest way

giuseppe.salvatore
2020-11-04 20:46
Thanks Matt that helps

antonello
2020-11-04 20:51
I?d use the maven plugin if you?re already using maven though. Any reason why you may not want to?

uglyog
2020-11-04 22:01
You will have to enable debug level logs to see what is happening.

uglyog
2020-11-04 22:02
That's a test project to check that the publishing works.

marzieh312
2020-11-05 00:55
has joined #pact-jvm

aliaksandr.valadzko
2020-11-05 09:37
Hey guys! I've discussed it in *pact-broker* channel, and it looks like I should proceed here `CanIDeploy` can use `--retry-while-unknown` parameter to poll broker until verification result be published https://docs.pact.io/pact_broker/client_cli/readme#can-i-deploy Is it planned to add this feature to _gradle_ *PactCanIDeployTask* ? Thanks in advance!

uglyog
2020-11-05 09:40
Please raise an issue for that, there is no current plan

aliaksandr.valadzko
2020-11-05 09:47
Thanks, cool! Is my issue filed correct?

giuseppe.salvatore
2020-11-05 10:49
I can of course, I was just wondering if I needed the provider plugin in the consumer or there was a consumer plugin

antonello
2020-11-05 10:53
it?s a bit confusing, but yes - you do need it in the consumer to publish :slightly_smiling_face:

giuseppe.salvatore
2020-11-05 11:10
The only reason why we are thinking about using the CLI is because we are building pipelines in Jenkins X dynamically using a script when a service is created. If we can "reuse" a pipeline step configuration that is not dependent on the actual technology it would be much better and can be used as is not only for maven but also gradle, node.js, python

giuseppe.salvatore
2020-11-05 11:10
I am not entirely sure that is going to play nicely but I though it was worth to investigate

pavank
2020-11-05 17:29
Hi Team, Need help in matching the request body, I have request in which I have field like "fulfilmentType":["SSHIP"] can anyone help to write matching for this please

ukrainian1991
2020-11-05 18:07
Hi, I need to create two PACT interaction. They are quite similar. Ther only differency is one nested field. I have used LambdaDslJsonBody to specify it. Is there a way to create the second interaction without code duplication?

ukrainian1991
2020-11-05 18:49
I've written a method which provides the proper object, but may be there is more handy way, e.g. some lambla tricks

matt.fellows
2020-11-06 04:08
@wilkinsweiqiangliang :point_up:

wilkinsweiqiangliang
2020-11-06 04:08
has joined #pact-jvm

wilkinsweiqiangliang
2020-11-06 04:15
Thanks for the quick fix @uglyog @matt.fellows

linda.anthu
2020-11-06 11:52
has joined #pact-jvm

linda.anthu
2020-11-06 14:27
hello :slightly_smiling_face: can anyone help me ? I wanted to update a field on request but I always get timeout :(

linda.anthu
2020-11-06 14:28
```describe("get football market information", () => { let opts: any; before((done) => { opts = { providerBaseUrl: conf.provider[0].BASE_URL, pactBrokerUrl: conf.pact_broker.URL, provider: conf.provider[0].NAME, publishVerificationResult: true, providerVersion: conf.provider[0].VERSION, requestFilter: (req: any, _res: any, next: any) => { if (req.path.match("/api")) { const chunks: any[] = []; req.on("data", function (chunk: any) { chunks.push(chunk); }); req.on("end", function () { req.body = JSON.parse(Buffer.concat(chunks).toString()); if (req.body.params.filter.marketIds) { req.body.params.filter.marketIds = [marketId]; } next(); }); } else { next(); } }, }; done(); }); it("validates the expectations of Matching Service", (done) => { return new Verifier(opts).verifyProvider() .then(output => { done(); }) .catch((error) => { done(error); }); }); });```

chandanakurumeti27
2020-11-09 10:28
Hi, I am about to write provider tests for the service, Right now I can see the option of starting the provider service at some port using jar file and run the provider tests against that port where i start the service using jar file.

chandanakurumeti27
2020-11-09 10:28
Is this how pact provider tests needs to be done?

chandanakurumeti27
2020-11-09 10:29
My main question/doubt here is that do i really need to use the jar file to start the service before running the provider tests or any other option available?

chandanakurumeti27
2020-11-09 10:29
FYI, Am pointing this jar file to talk to some other mocks when it got some request call

chandanakurumeti27
2020-11-09 10:30
Please reply if i can provide any further info on my question here

chandanakurumeti27
2020-11-09 10:30
Looking forward to any usefull explanation :slightly_smiling_face:

chandanakurumeti27
2020-11-09 10:30
Thank you!

ukrainian1991
2020-11-09 10:40
Hi, what could be the reason when provider verification finishes with : There are no consumers to verify for provider 'Provider_Name' When I see this pact contact in Broker and even could get this pact via manual API execution ```http://xx.xx.xx.xx/pacts/provider/Provider_Name/consumer/Consumer_Name/``` gradle plugin 4.1.6

ukrainian1991
2020-11-09 10:41
Exactly the same code is working for one more provider (another one)

matt.fellows
2020-11-09 10:54
So that is just one option for verification. There are other ways of starting your service from within the context of a test framework. e.g. if you use a spring boot app, you can use the spring test annotations to start the service in say, a JUnit test

matt.fellows
2020-11-09 10:54
There is nothing wrong with doing it your way, and then using a CLI tool to do the verification either

matt.fellows
2020-11-09 10:57
See the spring examples at pactflowexamples


chandanakurumeti27
2020-11-09 11:17
Thank you @matt.fellows, Just wanted to confirm using jar file to start the service is a good option or not as am using pact jvm framework

chandanakurumeti27
2020-11-09 11:17
That helped :slightly_smiling_face:

ukrainian1991
2020-11-09 14:45
I've found that gradle pactVerify_A_B autogenerated task does not work

uglyog
2020-11-09 22:01
If there are filters applied. For instance, if you have added the `@Consumer` annotation with a different name than `Consumer_Name`

uglyog
2020-11-09 22:02
In what way does it not work?

pbobba
2020-11-09 23:03
has joined #pact-jvm

jun.li
2020-11-09 23:05
has joined #pact-jvm

jun.li
2020-11-09 23:08
is it possible to divide a single provider test into two different unit test files

jun.li
2020-11-09 23:10
let's say a provider has 6 states, is it possible to put 3 states in one file and the other 3 states in a different file

uglyog
2020-11-09 23:10
Yes, there is no requirement to have them all in the same file

pbobba
2020-11-10 03:08
Hi all, I'm a newbie to Java and pact testing I'm trying to write my first consumer-driven pact test. I have the endpoint, request body and response to my provider. Can someone please help me out with building `RequestResponsePact` for it. Thanks in advance. More in thread.


pbobba
2020-11-10 03:14
Specific question: Is there a way to specify request body in the builder? Are there any good examples out there which reaches out to providers with request bodies. The examples I found so far are using query parameter names Eg: https://github.com/Mikuu/Pact-JVM-Example


uglyog
2020-11-10 03:17
The request body is constructed in the same way as the response one


pbobba
2020-11-10 03:21
awesome. Thank you!

douweicai
2020-11-10 04:11
has joined #pact-jvm

jun.li
2020-11-10 05:08
But If I put 3 ABC states in file A and put 3 DEF states in file B, when I run the test on file A it will say i am missing states DEF

uglyog
2020-11-10 06:15
Put them in a base class or interface



jun.li
2020-11-10 06:22
thanks i will try it out

christian.huber
2020-11-10 09:20
has joined #pact-jvm

christian.huber
2020-11-10 09:46
Hi all, has anyone successfully used pact in an Android project? I am trying to create an instrumented test that uses the app?s client classes to parse the response. When calling `ConsumerPactBuilder#uponReceiving` the test crashes with this cause: ``` ... 40 more Caused by: org.xml.sax.SAXNotRecognizedException: http://javax.xml.XMLConstants/feature/secure-processing at org.apache.harmony.xml.parsers.SAXParserFactoryImpl.setFeature(SAXParserFactoryImpl.java:93) at org.apache.tika.mime.MimeTypesReader.newSAXParser(MimeTypesReader.java:392) ... 42 more``` After quite some debugging it seems to me that creating `TikaConfig` in `OptionalBody` causes a scan for available MimeTypes which requires a SaxParser. The implementation `org.apache.harmony.xml.parsers.SAXParserFactoryImpl` used by the android runtime does not recognize the feature `http://javax.xml.XMLConstants/feature/secure-processing` and fails with an exception. I tried the following dependencies: `au.com.dius.pact.consumer:junit`, `au.com.dius.pact.consumer:java8` and `au.com.dius.pact:consumer` all in Version 4.1..10 but all fail with the same error. So far I have not found a way to either change the factory implementation class or disable the feature. Is that a known issue? Am I missing something obvious? Any pointers would be greatly appreciated.

jun.li
2020-11-10 10:12
``` [from Pact Broker https://xxxxxx.pactflow.io/pacts/provider/xxxxxxxxxxxxxxxx] a xxxxxxxxxxx event generates a message which Verification Failed - com.xxxxx.xxxxxxxx.PactProviderInterface Failures: 1) a xxxxxxxx event 1.1) com.xxxxx.xxxxxxxx.PactProviderInterface 21:10:32.520 [Test worker] WARN a.c.d.p.p.DefaultTestResultAccumulator - Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true')``` I just found the error message is not very clear

jun.li
2020-11-10 10:13
it didn't tell me where went wrong

vuttithatkrongyot
2020-11-10 10:57
has joined #pact-jvm

mmotornyi.consultant
2020-11-10 15:17
Is it possible to use kind of conditional verification. E.g. `if (array contains object with some filed) then verify this object like using exact matcher` ?

dan.iosif
2020-11-10 17:06
has joined #pact-jvm

uglyog
2020-11-10 22:07
Can you raise an issue for this with the full stack trace and any logging?


pbobba
2020-11-10 23:53
@uglyog Sorry for the direct ping but do you know at which point are we mocking the provider using pact in this example? https://github.com/pact-foundation/pact-jvm/blob/master/consumer/junit/src/test/java/au/com/dius/pact/consumer/junit/examples/ExampleServiceConsumerTest.java

abubics
2020-11-11 02:08
To answer your question, yes, I've used Pact in Android projects before :slightly_smiling_face: not for a couple of years, now, though.

abubics
2020-11-11 02:10
I've never had it set up as an instrumented test, always unit test. I would try to separate it from being platform-bound (unless you have some constraint that I haven't seen before).

pbobba
2020-11-11 05:05
Hi all, I'm seeing an issue while trying to write consumer-driven test in junit5 posted question in detail here: https://stackoverflow.com/questions/64780743/consumer-pact-test-pact-jvm-junit5-how-do-mock-the-provider-using-pact Any help is appreciated. Thanks in advance!

uglyog
2020-11-11 06:17
Not sure I understand the question. The mock server is provided by the test framework, and exists for the duration of the test method

anddreiu
2020-11-11 06:49
Hi all. I have an issue when using tags on my pact files and I don't know what's wrong in my implementation. I am using pact jvm 4.1.10, Pact Broker 2.68.1 and I am using JUnit to run the Provider tests. I am trying to use tags to retrieve the correct pact file when running the Provider tests for a specific consumer. So I've applied the below consumerVersionSelectors: ```@PactBroker(consumerVersionSelectors = { @VersionSelector(tag = "prod", consumer = "consumerName") }``` Unfortunately, the pact file retrieved is the latest one published in Pact Broker and it looks like it does not see the consumer that I've indicated above (also, it does not have prod tag): ```2020-11-11 06:39:28.637 DEBUG [PactBrokerLoader.kt] Loading pacts from pact broker for provider providerName and consumer version selectors [ConsumerVersionSelector(tag=prod, latest=true, consumer=null, fallbackTag=)] Verifying a pact between consumerName and providerName Notices: 1) The pact at https://pactbroker/pacts/provider/providerName/consumer/consumerName/pact-version/64fr34ca943bbg242432we3f9hwe43c34r25wef2 is being verified because it matches the following configured selection criterion: latest pact for a consumer version tagged 'prod'``` Does anybody know what I am doing wrong here? Thank you!

uglyog
2020-11-11 06:55
That looks like a defect ```[ConsumerVersionSelector(tag=prod, latest=true, consumer=null, fallbackTag=)]```

anddreiu
2020-11-11 07:09
ok, in this case I will raise a GitHub issue

christian.huber
2020-11-11 08:36
I was afraid that might be issue :wink: Thanks for the input. Will try to put up an issue.

francislainy.campos
2020-11-11 08:39
Hi, not sure if it would answer your question directly, but this article may help you a bit. https://hmh.engineering/how-to-write-and-validate-pact-contracts-using-junit5-and-restassured-72b578e7dd65

anddreiu
2020-11-11 09:11
I've just tried to use the deprecated version of this: ```@PactBroker(consumers = "consumerName", tags = "prod"``` In this case the right consumer is taken (see below), but the retrieved pact is not the correct one: ```2020-11-11 09:08:24.084 DEBUG [PactBrokerLoader.kt] Loading pacts from pact broker for provider providerName and consumerName version selectors [ConsumerVersionSelector(tag=prod, latest=true, consumer=consumerName, fallbackTag=null)]``` The retrieved pact is the latest one, even if this does not have 'prod' tag. Very weird

aliaksandr.valadzko
2020-11-11 09:28
Hello guys! Is there an opportunity to extract this _HttpTarget_ constructor parameters to _SpringContext_? ``` @TestTarget public final Target target = new HttpTarget("http", "localhost", 9080, "/api");``` I use `org.springframework.test.context.ContextConfiguration` : ```@ContextConfiguration(classes = {PactContext.class})``` However getting `nulls` for this variant: ``` @Value("${test.target.scheme}") String scheme; ..... @TestTarget public final Target target = new HttpTarget(scheme, host, port, path);```

aliaksandr.valadzko
2020-11-11 10:49
One more question: Do you know what might be reason of this failure? ```java.lang.NoSuchMethodError: java.lang.NoSuchMethodError: au.com.dius.pact.core.model.HttpPart.determineContentType()Lau/com/dius/pact/core/model/ContentType; java.lang.NoSuchMethodError: au.com.dius.pact.core.model.HttpPart.determineContentType()Lau/com/dius/pact/core/model/ContentType; at au.com.dius.pact.core.matchers.Matching.matchBody(Matching.kt:58) at au.com.dius.pact.core.matchers.ResponseMatching.responseMismatches(ResponseMatching.kt:21) at au.com.dius.pact.provider.ResponseComparison$Companion.compareResponse(ResponseComparison.kt:120) at au.com.dius.pact.provider.ProviderVerifier.verifyRequestResponsePact(ProviderVerifier.kt:480) at au.com.dius.pact.provider.ProviderVerifier.verifyResponseFromProvider(ProviderVerifier.kt:561) at au.com.dius.pact.provider.junit.target.HttpTarget.testInteraction(HttpTarget.kt:73) at au.com.dius.pact.provider.junit.InteractionRunner$interactionBlock$statement$1.evaluate(InteractionRunner.kt:204) at au.com.dius.pact.provider.junit.RunStateChanges.evaluate(RunStateChanges.kt:20) at au.com.dius.pact.provider.junit.RunStateChanges.evaluate(RunStateChanges.kt:20) at au.com.dius.pact.provider.spring.SpringBeforeRunner.evaluate(SpringInteractionRunner.kt:32) at au.com.dius.pact.provider.spring.SpringAfterRunner.evaluate(SpringInteractionRunner.kt:48) at au.com.dius.pact.provider.junit.InteractionRunner.run(InteractionRunner.kt:145) at au.com.dius.pact.provider.junit.PactRunner.runChild(PactRunner.kt:147) at au.com.dius.pact.provider.junit.PactRunner.runChild(PactRunner.kt:52) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)``` `au.com.dius.pact.consumer:junit:4.1.7` Thanks in advance

chandanakurumeti27
2020-11-11 11:09
Hi;

chandanakurumeti27
2020-11-11 11:10
Am trying to publish pacts to pact broker with tags using maven plugin

chandanakurumeti27
2020-11-11 11:11
And am sure that it is possible from this discussion https://github.com/pact-foundation/pact-jvm/issues/403

chandanakurumeti27
2020-11-11 11:11
Am using `pact-jvm-provider-maven 4.0.0` version plugin

chandanakurumeti27
2020-11-11 11:12
Can some one please provide me the examples to refer for tags setup

chandanakurumeti27
2020-11-11 11:12
Looking forward to any help!

chandanakurumeti27
2020-11-11 11:12
Thanks

chandanakurumeti27
2020-11-11 11:12
:slightly_smiling_face:

chandanakurumeti27
2020-11-11 11:13
My question/doubt is more like , where do i need to include the tags details inside the code

chandanakurumeti27
2020-11-11 11:13
is it in pom.xml or inside the consumer test file?

antonello
2020-11-11 11:15
Have you seen this in the docs? ```<plugin> <groupId>au.com.dius.pact.provider</groupId> <artifactId>maven</artifactId> <version>4.1.0</version> <configuration> <pactDirectory>path/to/pact/files</pactDirectory> <!-- Defaults to ${project.build.directory}/pacts --> <pactBrokerUrl>http://pactbroker:1234</pactBrokerUrl> <projectVersion>1.0.100</projectVersion> <!-- Defaults to ${project.version} --> <tags> <tag>feature/feature_name</tag> </tags> </configuration> </plugin>```


antonello
2020-11-11 11:23
You don?t have to hardcode the tag there though, as the value of `<tag>` can be a properties that you can pass to maven, e.g. ```<tags> <tag>${pactbroker.consumerTag}</tag> </tags>```

antonello
2020-11-11 11:23
then you can pass `-Dpactbroker.consumerTag=<your-tag>` to maven.

uladzislau_danilchyk
2020-11-11 11:51
@aliaksandr.valadzko I've got the same! But have found a solution. Try to use `@PostConstruct` like this: ``` @TestTarget public Target target; @PostConstruct private void before() { target = new HttpTarget(targetScheme, targetHost, targetPort); }```

aliaksandr.valadzko
2020-11-11 11:52
Cool, will try!

uladzislau_danilchyk
2020-11-11 11:52
it works for me.

chandanakurumeti27
2020-11-11 11:54
Thanks for your reply, will try that :slightly_smiling_face:

aliaksandr.valadzko
2020-11-11 11:57
Thanks a lot!!!

aliaksandr.valadzko
2020-11-11 11:57
It works!

uladzislau_danilchyk
2020-11-11 11:57
Great!

aliaksandr.valadzko
2020-11-11 12:14
Resolved - transitive issue :white_check_mark:

almaak
2020-11-11 13:33
hey all, is there a way to take some field from the consumer request and add it to the mocked response? thank you.

pbobba
2020-11-11 14:25
I see internal server error when trying to reach to the mock provider. I stated the problem clearly in this https://stackoverflow.com/questions/64780743/consumer-pact-test-pact-jvm-junit5-how-to-mock-the-provider-using-pact

ukrainian1991
2020-11-11 14:59
I updated gradle plugin version to 4.1.10 from 4.1.6 and it works

ukrainian1991
2020-11-11 15:01
Seems there was a bug, when two Service providers are described in build.gradle and you try to call task for the second one

almaak
2020-11-11 19:45
hey again, @uglyog, I'm having problems with the dependencies, apparently I'm not using the correct versions. do you have some pom with the correct versions of the dependencies for "au.com.dius.pact:pact-jvm-server:4.1.7"? thank you.

matt.fellows
2020-11-11 20:34
Can you elaborate as to why you couldn't do that already? A consumer test is a unit test, so you should already have full control over the mock and what request you're going to send

giuseppe.salvatore
2020-11-11 21:34
Hi guys... I keep getting this error: ```[ERROR] Failures: [ERROR] SubscriptionUsageHistoryMockConsumerVerificationTest 0 - Expected a response type of 'application/json' but the actual type was 'text/plain' 1 - Expected a header 'Content-Type' but was missing [INFO] [ERROR] Tests run: 9, Failures: 1, Errors: 0, Skipped: 0``` which makes sense because I believe it's default error response for SpringBoot when you are missing a mandatory header with curl I get ```* Mark bundle as not supporting multiuse < HTTP/1.1 400 Bad Request < Server: nginx/1.17.10 < Date: Wed, 11 Nov 2020 21:31:30 GMT < Content-Length: 0 < Connection: keep-alive < x-envoy-upstream-service-time: 3``` My question: is there a way to relax the check that PACT verification performs? After all I am happy if I get a 400 for a malformed request

abubics
2020-11-11 21:37
Is your test expecting a 400, and not specifying a content type? Or is this interaction failing, and the output is just confusing?

abubics
2020-11-11 21:42
I mean, whether it's instrumented or not, you should still be able to run it without exceptions :thumbsup: but reducing the number of moving parts may help you debug it. More as an aside, your API client is probably testable as a unit separate from Tika :innocent:


uglyog
2020-11-11 22:08
`pact.consumer.tags Overrides the tags used when publishing pacts [version 4.0.7+]`

uglyog
2020-11-11 22:08
You need version 4.0.7 or later

uglyog
2020-11-11 22:09
No pom, but you can refer to the Gradle build for it


uglyog
2020-11-11 22:10
The other option is to download the application archive for it and look at all the dependencies for it in there

uglyog
2020-11-11 22:10
> Page not found > This question was voluntarily removed by its author.

rodrigo.costa20
2020-11-12 00:59
has joined #pact-jvm

rodrigo.costa20
2020-11-12 01:01
Hello everyone! I'm new at using Pact... I'm having a problem that I would like to see if anyone know what am I doing wrong...

rodrigo.costa20
2020-11-12 01:01
I have just configurated the provider side on my tests

rodrigo.costa20
2020-11-12 01:01
however, when I try to run the tests, i keep getting the error "No tests were found"

rodrigo.costa20
2020-11-12 01:02
I'm using the Junit runner, its a Java EE application

rodrigo.costa20
2020-11-12 01:02
do you guys have any idea, about what I may be doing something wrong?

uglyog
2020-11-12 01:04
How are you running the tests? With Maven, Gradle or an IDE?

rodrigo.costa20
2020-11-12 01:07
IDE - intellij

rodrigo.costa20
2020-11-12 01:08
also, its a maven project

rodrigo.costa20
2020-11-12 01:24
this is the error that I'm getting

uglyog
2020-11-12 01:28
That means the classpath is not setup correctly in your IDE. Maybe look at the IntelliJ IDEA docs for using Maven projects.


rodrigo.costa20
2020-11-12 01:33
I'm able to run other kind of tests by IDE... do you have any suggestion, about what can be wrong in this case? Also, I've tried to run the pact tests from command line with maven... but in this case this is the error that I got: `pact-jvm-provider-maven:4.0.10:verify failed: lateinit property serviceProviders has not been initialized`

young
2020-11-12 03:34
Hi team, about provider state confused me for many days, and I had to ask for help here. Thanks in advance. The below is my code: ```ProviderStateRequest.java @Getter @Setter @NoArgsConstructor @ApiModel(description = "Provider state request") public class ProviderStateRequest { @ApiModelProperty(value = "provider state name") private String name; @ApiModelProperty(value = "provider state params") private Map<String,Object> params; }``` ```PactStateController.java @RestController @RequestMapping(path = "/api/pact") public class PactStateController { private final WalletService walletService; @Autowired public PactStateController(WalletService walletService) { this.walletService = walletService; } @PostMapping("/providerState") @ApiOperation(value = "Pact state change url to prepare the data") @NeuronSecured(permissions = PermissionConstants.WRITE, resource = PermissionConstants.RESOURCE_FINANCE) public BasicResponse<Boolean> stateChangeForRefund(@RequestBody ProviderStateRequest providerStateRequest) { int userId; switch (providerStateRequest.getName()) { case "wallet.balance=0": userId = Integer.parseInt(providerStateRequest.getParams().get("userId").toString()); walletService.emptyBalance((long)userId); break; default: return new BasicResponse<>(false); } return new BasicResponse<>(true); } }``` ```build.gradle ........ pact { broker { pactBrokerUrl = "http://xx.xx.xx.xxx" pactBrokerUsername = "admin" pactBrokerPassword = "admin" } serviceProviders { NeuronPublic { protocol = 'http' host = 'localhost' port = 8080 path = '/' requestFilter = { req -> req.addHeader('testmode','true') req.addHeader('X-Authorization','Bearer your token') } hasPactWith('local') { stateChangeUrl = new URL('http://localhost:8080/api/pact/providerState') pactSource = file("$rootDir/Pacts/NeuronShareQA-NeuronPublic.json") } } } }``` When I run the ./gradlew pactVerify, I will get the below error: ```1) Verifying a pact between local and NeuronPublic - /api/finance/v1/top-up 1.1) State change callback failed with an exception - State Change Request Failed - HTTP/1.1 400 > Task :pactVerify_NeuronPublic FAILED FAILURE: Build failed with an exception. * What went wrong: There were 1 non-pending pact failures for provider NeuronPublic``` I really don't know what's the root cause, Pls help. Thanks.:slightly_smiling_face:

uglyog
2020-11-12 03:35
You haven't specified any serviceProviders in your POM


uglyog
2020-11-12 03:38
The call to the state change URL returned a 400 error. You'll need to work out why it did that

uglyog
2020-11-12 03:38
Try turn on debugging, look at the Springboot logs, etc.

matt.fellows
2020-11-12 03:39
``` @ApiModelProperty(value = "provider state name") private String name;```

matt.fellows
2020-11-12 03:39
Is that a json attribute mapping?


matt.fellows
2020-11-12 03:41
The incoming payload will be more like: `{ "state" : "a provider state description", "params": { "a": "1", "b": "2" } }`

young
2020-11-12 03:44
Thanks will try

young
2020-11-12 03:45
Thanks Matt, But why the pact file indicated that "name"?

matt.fellows
2020-11-12 03:55
I?m not sure, sorry. that?s just how the pact file stores it.

young
2020-11-12 03:58
thank you all the same. I changed the "name" to "state", responsed http code 400 as well.

young
2020-11-12 04:08
Hi @uglyog Can you help to analyze this log if you are free? Thank you. ```12:04:08.480 [DEBUG] [org.apache.http.impl.execchain.MainClientExec] Opening connection {}->http://localhost:8080 12:04:08.481 [DEBUG] [org.apache.http.impl.conn.DefaultHttpClientConnectionOperator] Connecting to localhost/127.0.0.1:8080 12:04:08.481 [DEBUG] [org.apache.http.impl.conn.DefaultHttpClientConnectionOperator] Connection established 127.0.0.1:63400<->127.0.0.1:8080 12:04:08.482 [DEBUG] [org.apache.http.impl.execchain.MainClientExec] Executing request POST /api/pact/providerState HTTP/1.1 12:04:08.482 [DEBUG] [org.apache.http.impl.execchain.MainClientExec] Target auth state: UNCHALLENGED 12:04:08.482 [DEBUG] [org.apache.http.impl.execchain.MainClientExec] Proxy auth state: UNCHALLENGED 12:04:08.828 [DEBUG] [au.com.dius.pact.provider.DefaultStateChange] Invoked state change http://localhost:8080/api/pact/providerState -> HTTP/1.1 400 12:04:08.829 [QUIET] [system.out] State Change Request Failed - HTTP/1.1 400 12:04:08.829 [DEBUG] [org.apache.http.impl.conn.DefaultManagedHttpClientConnection] http-outgoing-5: Close connection 12:04:08.829 [DEBUG] [org.apache.http.impl.execchain.MainClientExec] Connection discarded 12:04:08.829 [DEBUG] [org.apache.http.impl.conn.PoolingHttpClientConnectionManager] Connection released: [id: 5][route: {}->http://localhost:8080][total kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 10] 12:04:08.829 [DEBUG] [au.com.dius.pact.provider.DefaultStateChange] State Change: "ProviderState(name=wallet.balance=0, params={userId=42404})" -> Err(java.lang.Exception: State Change Request Failed - HTTP/1.1 400 ) 12:04:08.830 [QUIET] [system.out] 12:04:08.830 [QUIET] [system.out] NOTE: Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true') 12:04:08.830 [QUIET] [system.out] 12:04:08.830 [QUIET] [system.out] 12:04:08.830 [QUIET] [system.out] Failures: 12:04:08.830 [QUIET] [system.out] 12:04:08.830 [QUIET] [system.out] 1) Verifying a pact between local and NeuronPublic - /api/finance/v1/top-up 12:04:08.830 [QUIET] [system.out] 12:04:08.830 [QUIET] [system.out] 1.1) State change callback failed with an exception - State Change Request Failed - HTTP/1.1 400 12:04:08.831 [QUIET] [system.out] 12:04:08.831 [QUIET] [system.out] 12:04:08.831 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Execute verifyPact for :pactVerify_NeuronPublic' 12:04:08.831 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Execute verifyPact for :pactVerify_NeuronPublic' completed 12:04:08.831 [DEBUG] [org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter] Removed task artifact state for {} from context. 12:04:08.831 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':pactVerify_NeuronPublic' 12:04:08.831 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Task :pactVerify_NeuronPublic' 12:04:08.831 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Task :pactVerify_NeuronPublic' completed 12:04:08.831 [INFO] [org.gradle.execution.taskgraph.DefaultTaskPlanExecutor] :pactVerify_NeuronPublic (Thread[Daemon worker Thread 13,5,main]) completed. Took 0.392 secs. 12:04:08.832 [DEBUG] [org.gradle.internal.resources.AbstractTrackedResourceLock] Daemon worker Thread 13: released lock on : 12:04:08.832 [DEBUG] [org.gradle.internal.work.DefaultWorkerLeaseService] Worker lease root.1.19 completed (1 worker(s) in use) 12:04:08.832 [DEBUG] [org.gradle.internal.resources.AbstractTrackedResourceLock] Daemon worker Thread 13: released lock on root.1.19 12:04:08.832 [DEBUG] [org.gradle.execution.taskgraph.DefaultTaskPlanExecutor] Task worker [Thread[Daemon worker Thread 13,5,main]] finished, busy: 0.395 secs, idle: 8.094 secs```

matt.fellows
2020-11-12 05:22
no worries

matt.fellows
2020-11-12 05:22
my point was, check the mapping :slightly_smiling_face:

matt.fellows
2020-11-12 05:23
Do you use JUnit by any chance? Because if you do, it might be easier to go down that path rather than the gradle path where you need to setup a state handler endpoint

matt.fellows
2020-11-12 05:23
You probably need to enable logs on your spring boot app. From this, we can?t see why your endpoint failed

matt.fellows
2020-11-12 05:24
you can see clearly the payload that was sent over `POST` to `/api/pact/providerState` but we can?t see what your app did, besides returning a `400`

young
2020-11-12 05:33
Thank you matt, the "Request params invalid" error shown, ```[A][2020-11-12 13:30:54,198][INFO ][http-nio-8080-exec-2][AccessLoggingFilter][doFilterInternal][] - {"clientIp":"127.0.0.1","method":"POST","uri":"/api/pact/providerState","processTime":60,"params":"{}","body":"{\"state\":\"wallet.balance\u003d0\",\"params\":{\"userId\":\"42404\"}}","headers":"{\"user-agent\":\"Apache-HttpClient/4.5.5 (Java/1.8.0_201)\"}","status":400,"response":"{\"message\":\"Request params invalid\",\"detailed\":\"Request params invalid\",\"errorCode\":\"INVALID_REQUEST\",\"timestamp\":\"2020-11-12T13:30:54+0800\"}"}```

young
2020-11-12 05:34
I will try again

yong.gong188
2020-11-12 09:13
has joined #pact-jvm

giuseppe.salvatore
2020-11-12 10:05
Yeah my test is expecting a 400 but doesn't specify anything about the content type. But the interaction is failing because it expects it to have a `Content-Type: application/json` . As I didn't specify that anywhere I though it was the framework doing that check, maybe given the request is in `application/json` it checks also the response is

anandhadeepak
2020-11-12 13:03
has joined #pact-jvm

abubics
2020-11-12 13:11
I feel like there was a query about that in the last few months, but I don't remember the outcome. I think it was suggested that defaulting to expect `application/json` was bad, but I'm not sure if it was going to be remedied or not. Maybe @bethskurrie or @uglyog remembers?

david.dias
2020-11-12 20:04
has joined #pact-jvm

uglyog
2020-11-12 22:02
What version of Pact-JVM are you using?

mmotornyi.consultant
2020-11-13 07:21
Ok, thank you.

almaak
2020-11-13 08:27
ok, thanks. I've listetd all the libs from the app archive.

billal.patel
2020-11-13 10:31
has joined #pact-jvm

wesleythomaswilliams
2020-11-13 12:18
@uglyog I'm curious, why does this method default the number of examples to 2? ``` public PactDslJsonBody minArrayLike(String name, Integer size, PactDslJsonRootValue value) { return this.minArrayLike(name, size, value, 2); }```

dattasai.chunduru
2020-11-13 12:54
Hi All can anyone please help me in doing provider side validation with Request headers. I am using the below code snippet . But system is showing me error as shown below

francislainy.campos
2020-11-13 13:46
Could you share your pom dependencies for pact and junit and the pact code?

uglyog
2020-11-14 02:43
That's a good question. I don't know.

uglyog
2020-11-14 02:44
Maybe having 2 instead of 1 examples was felt to be better representation of what a real array would have :man-shrugging:

uglyog
2020-11-14 02:46
You are getting connection refused on port 8083 because there is nothing running on that port. Have you started the provider you are trying to verify?

louis.oliver
2020-11-16 10:33
has joined #pact-jvm

billal.patel
2020-11-16 14:45
@billal.patel has left the channel

ashishkujoy
2020-11-16 15:08
has joined #pact-jvm

pradeepchoube
2020-11-17 03:49
has joined #pact-jvm

meng-lingtao
2020-11-17 14:39
has joined #pact-jvm

pabvidcal
2020-11-17 15:30
has joined #pact-jvm

magesh.nagamani
2020-11-18 05:15
has joined #pact-jvm




antonello
2020-11-18 07:05
For future reference, it is possible to do a search on the entire repository.

antonello
2020-11-18 07:06
Welcome @magesh.nagamani !

magesh.nagamani
2020-11-18 07:07
Appreciate the help @antonello Thank you!

matt.fellows
2020-11-18 07:50
Better yet, use the search on this site: https://docs.pact.io/implementation_guides/jvm

matt.fellows
2020-11-18 07:50
All of the language docs are copied there and the search is much better

ashish_garg5
2020-11-18 08:08
Hi All, Just wanted to confirm what this below method does. Does it checks the tag of consumer or it checks for provider ? `java.lang.String[]*tags*()` Tags to use to fetch pacts for, defaults to `latest` If you set the tags through the `pactbroker.tags` system property, separate the tags by commas. Thanks

matt.fellows
2020-11-18 09:05
It sounds like Consumer tags

matt.fellows
2020-11-18 09:06
What is the context of it being used

ashish_garg5
2020-11-18 10:35
* Tags to use to fetch pacts for, defaults to `latest` * If you set the tags through the `pactbroker.tags` system property, separate the tags by commas */ String[] tags() default "${pactbroker.tags:latest}";

ashish_garg5
2020-11-18 10:35
this method i was asking for which is there inside the PactBroker interface

ashish_garg5
2020-11-18 10:36
i think it is checking both consumer and provider

matt.fellows
2020-11-18 10:58
I think you?re referring to https://docs.pact.io/implementation_guides/jvm/provider/junit/#using-tags-with-the-pact-broker, which in that case, we are referring to the consumer tags. Provider tags are, unsurprisingly, referred to as `providerTags` (see https://docs.pact.io/implementation_guides/jvm/provider/junit/#pending-pact-support-version-413-and-later) and are used to calculate pending pacts

ashish_garg5
2020-11-18 11:02
yeah i was looking for this only... Thanks :slightly_smiling_face:

jstoebel
2020-11-18 13:53
has joined #pact-jvm

borsuk.artem034
2020-11-18 17:03
Hello, I can't decide what test should I use for consumer pact test unit or integration, for one side recommendation use unit tests, but I will test just mocks, for other side integration test give more coverage and log time execution. So I what to hear other opinion :slightly_smiling_face: add few examples in thead

borsuk.artem034
2020-11-18 17:04
```Unit @Test @PactVerification(fragment = "createPact") public void verifyPact() { eventConsumer.handleEvent(messageProvider.getMessage()); String json = "{someKey: \"someVale\"}"; assertEquals(json, messageProvider.getMessage()); }```

borsuk.artem034
2020-11-18 17:05
```Integration @Test @PactVerification(fragment = "createPact") public void verifyPact() { //init in-memory DB or testcontainers..... eventConsumer.handleEvent(messageProvider.getMessage()); assertEquals(dbRepository.getInfo(), messageProvider.getMessage()); }```

wilkinsweiqiangliang
2020-11-18 22:47
#pact-jvm i wonder if the consumer can make sure an ID field(String) type not returning `NULL` from provider?

wilkinsweiqiangliang
2020-11-18 22:48
```24  export const expectedObject = 25    { 26      id: uuid("da16494a-303a-463c-919a-e29e03a5b1de") 27 }```

uglyog
2020-11-18 22:54
That should not allow NULLs, only strings that match a UUID

wilkinsweiqiangliang
2020-11-18 22:55
in Java side, string is nullable

wilkinsweiqiangliang
2020-11-18 22:55
does it mean i need to enhance the test a bit to cover the nullable case?

uglyog
2020-11-18 22:58
You need two tests, one when it is not NULL, and one where it is

wilkinsweiqiangliang
2020-11-18 23:01
:+1:

daniel.sayer89
2020-11-19 10:33
has joined #pact-jvm

art.ptushkin
2020-11-19 10:34
has joined #pact-jvm

pact457
2020-11-19 10:36
has joined #pact-jvm

ajerthan.sivayoganath
2020-11-19 10:38
has joined #pact-jvm

philipchardwick
2020-11-19 11:05
has joined #pact-jvm

tanzmann
2020-11-19 11:09
has joined #pact-jvm

olivier.quere
2020-11-19 12:10
has joined #pact-jvm

wilfried.vandenberghe
2020-11-19 12:19
has joined #pact-jvm

alan.hanafy
2020-11-19 19:28
has joined #pact-jvm

michael.deutscher
2020-11-19 21:39
has joined #pact-jvm

gerry.power
2020-11-20 03:31
has joined #pact-jvm

alex900
2020-11-20 05:08
has joined #pact-jvm

tomas.panik
2020-11-20 08:28
has joined #pact-jvm

art.ptushkin
2020-11-20 08:56
Hey everyone! Any updates on merging HTTP and messaging pacts https://github.com/andreasevers/pact-demo/issues/1? Just got this problem, really don't want to rename the provider

matt.fellows
2020-11-20 11:39
It?s a proposal in the v4 spec, I?m not sure if Java supports it yet


matt.fellows
2020-11-20 11:40
There definitely isn?t broad support for it yet though

marc.ferland
2020-11-20 14:43
has joined #pact-jvm

sebastien.crapoulet
2020-11-20 15:24
has joined #pact-jvm

adutrillaux
2020-11-20 15:28
has joined #pact-jvm

he
2020-11-20 15:59
has joined #pact-jvm

ivgeni.slabkovski
2020-11-20 21:52
has joined #pact-jvm

serhatburakyildirim
2020-11-21 21:57
has joined #pact-jvm

alnasl
2020-11-22 18:46
has joined #pact-jvm

ashutosh23802
2020-11-23 06:20
has joined #pact-jvm

leonty
2020-11-23 10:33
has joined #pact-jvm

dariusz.piwko
2020-11-23 11:34
has joined #pact-jvm

uladzislau_danilchyk
2020-11-23 15:08
Hi everyone! I have a question regarding provider verification using junit5. I have a provider verification test as per docs. And I want to verify provider against specific pacts version (consumer version) which are stored in Pact Broker? How to do that? I want to pass consumer version before/during running of provider verification test. But no docs were found related to that. Could anyone help me?

phil.endsley
2020-11-23 15:14
I think typically, you would tag your consumer pact when you publish them to broker. Then, when you run your provider verification, you would specify that tag using `@PactBroker with @ConsumerVersionSelector`

antonello
2020-11-23 15:33
I?ve answered in #general

antonello
2020-11-23 15:33
I?ve assumed the use case is legitimate

antonello
2020-11-23 15:53
but you?re right, @phil.endsley, obviously :slightly_smiling_face:

antonello
2020-11-23 15:54
we use `pact.filter.pacturl=http://$BROKER_HOSTNAME:$BROKER_PORT/pacts/provider/$PROVIDER_NAME/consumer/$CONSUMER_NAME/version/$CONSUMER_VERSION` when we want to run some provider verification tests in CI against a specific consumer version

antonello
2020-11-23 15:55
Sometimes it?s happened that can-i-deploy on a consumer failed because of missing verifications

antonello
2020-11-23 15:55
so we?ve built a special job that verifies a specific consumer version

praneeth.kumar
2020-11-23 16:18
has joined #pact-jvm

mark.white
2020-11-24 09:03
has joined #pact-jvm

ufuk.ozcelik
2020-11-24 14:58
has joined #pact-jvm

stefanos.varsanis
2020-11-24 16:48
has joined #pact-jvm

lalexander2810
2020-11-24 16:53
has joined #pact-jvm

lalexander2810
2020-11-24 20:39
Hey everyone I wanted to know if there were any examples of fuzzy matching in pact. I am using the `eachLike` method to set the data type but my tests is still checking absolute value vs data type. Any ideas on how to implement this correctly?

sivaprasad9
2020-11-24 20:46
has joined #pact-jvm

phil.endsley
2020-11-24 20:50
You should be able to use the `...Type` methods for matching on data type stringType, numberType, etc... https://docs.pact.io/implementation_guides/jvm/consumer/#dsl-matching-methods

lalexander2810
2020-11-24 21:00
It seems like the `...Type` methods check for the data value as well it appears. I'm trying to limit the validation to strictly data types vs data type + value

phil.endsley
2020-11-24 21:02
For the consumer, they will check the value. The provider verification will be more lenient and only verify types. On the consumer side, you can use the example parameter to make the value used in the test deterministic. If you omit the example, pact chooses a random value for each test.

phil.endsley
2020-11-24 21:03
The assumption is since you're writing unit tests on the consumer, you should have full control over which values get returned, so making mocks return values matching the examples shouldn't be an issue

yann.courtel
2020-11-25 10:26
Hi guys, I wanted to know if it was at all possible to have a PACT between one consumer and one provider with interactions (http like) and messages at the same time? I know that responsibility wise, it's not correct but I'd like to know if it is possible in the PACT spectifications 3.0. Thanks a lot

matt.fellows
2020-11-25 11:02
You have to currently name them differently. In spec v4.0 it will be supported to allow both types in the same contract file

yann.courtel
2020-11-25 12:35
Thank you for the quick answer Matt :)

uladzislau_danilchyk
2020-11-25 14:48
Hi everyone! I have a Spring Boot app which is consumer and provider at the same time. I have following dependencies in gradle.build: ```testImplementation 'au.com.dius.pact.consumer:groovy:4.1.11' testImplementation 'au.com.dius.pact.provider:junit5:4.1.11'``` But after running VerificationTest it fails with: ```Could not find org.codehaus.groovy:groovy:4.1.11. Searched in the following locations: - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy/4.1.11/groovy-4.1.11.pom If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration. Required by: project :modules:shop > Could not find org.codehaus.groovy:groovy-ant:4.1.11. Searched in the following locations: - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy-ant/4.1.11/groovy-ant-4.1.11.pom If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration. Required by: project :modules:shop > Could not find org.codehaus.groovy:groovy-templates:4.1.11. Searched in the following locations: - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy-templates/4.1.11/groovy-templates-4.1.11.pom If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration. Required by: project :modules:shop``` Could anyone help me with that?

scyr
2020-11-25 14:56
has joined #pact-jvm

pavel.azarau
2020-11-25 18:32
Hello folks. Didn?t know what channel to use. I?m using Gradle plugin ?http://au.com.dius.pact? version ?4.1.9". I?ve configured it to access pactflow acc. And when I run `pactVerify` task I?m getting ```Failed to fetch the root HAL document au.com.dius.pact.core.pactbroker.RequestFailedException: Request to path '/' failed with response 'HTTP/1.1 400 Bad Request' at au.com.dius.pact.core.pactbroker.HalClient.handleHalResponse(HalClient.kt:301) at au.com.dius.pact.core.pactbroker.HalClient.access$handleHalResponse(HalClient.kt:140) at au.com.dius.pact.core.pactbroker.HalClient$getJson$1.invoke(HalClient.kt:284)``` However in Postman I can successfully perform a GET request using the same url and token I used to configure plugin

matt.fellows
2020-11-25 21:03
I've responded in your other post

pavel.azarau
2020-11-25 21:07
if anybody is interested the issue is solved with ugrade to 4.1.11

timotheus.ruprecht
2020-11-25 22:12
has joined #pact-jvm

uladzislau_danilchyk
2020-11-26 09:05
Hi! Currently I have error when running verification test: ```Could not resolve all files for configuration ':modules:shop:detachedConfiguration243'. 2020-11-26T12:01:44.861+0300 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Could not find org.codehaus.groovy:groovy:4.1.0. 2020-11-26T12:01:44.861+0300 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Searched in the following locations: 2020-11-26T12:01:44.861+0300 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] - https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy/4.1.0/groovy-4.1.0.pom 2020-11-26T12:01:44.861+0300 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration. 2020-11-26T12:01:44.862+0300 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Required by: 2020-11-26T12:01:44.862+0300 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] project :modules:shop 2020-11-26T12:01:44.862+0300 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Could not find org.codehaus.groovy:groovy-ant:4.1.0.```

uladzislau_danilchyk
2020-11-26 11:01
Could anyone help me with that? I don't understand why gradle tries to load groovy 4.1.0 as for consumer package...

abubics
2020-11-26 11:06
You could try inspecting the dependency tree, to work out which dependency is pulling it in . . . seems like the place to start is `:modules:shop`, if that means something to you?

uladzislau_danilchyk
2020-11-26 11:39
@abubics if you look at maven repo you will see that no such version of groovy dependencies

uladzislau_danilchyk
2020-11-26 11:40
@abubics but in logs 4.1.0 version is passed because of I have `testImplementation 'au.com.dius.pact.consumer:groovy:4.1.0'`

manali.mogre
2020-11-26 11:44
has joined #pact-jvm

uladzislau_danilchyk
2020-11-26 11:48
It's is reproducing on fresh project with junit and consumer groovy libs only

erik.terpstra
2020-11-26 12:08
has joined #pact-jvm

uladzislau_danilchyk
2020-11-26 13:22
How to enable debug for provider test? Because of kotlin files are used by Pact

kjayachandra2000
2020-11-26 20:40
has joined #pact-jvm

kjayachandra2000
2020-11-26 20:43
hey lads, how to run the pact provide tests from gradle and commandline

uglyog
2020-11-26 22:10
This has happened to me, and after a but of debugging I think it is a bug with the Gradle dependency resolution

uglyog
2020-11-26 22:11
Can't remember what I did to resolve it, but you can try cleaning out the Gradle cache (it is stored in `.gradle` in your home directory)

uglyog
2020-11-26 22:12
Depends on how you are running the provider tests


sushil.kumar
2020-11-27 01:45
has joined #pact-jvm

sushil.kumar
2020-11-27 01:47
Hi there! looking for info how to define self referencing object in PactDslJsonBody

uglyog
2020-11-27 01:52
What do you mean by a self referencing object?

uglyog
2020-11-27 01:52
Maybe an example JSON payload would help

sushil.kumar
2020-11-27 02:02
{ "product": { "id": "product-1", "name": "Lorem Ipsum product name", "subProducts": [ { "id": "nested-product-2", "name": "Lorem Ipsum product name", "subProducts": [] }, { "id": "nest-product3", "name": "Lorem Ipsum product name", "subProducts": [] } ] } }

uglyog
2020-11-27 02:03
Oh, you mean repeated

sushil.kumar
2020-11-27 02:03
in this json example, root body has an object "product" that in turn has an array "subProducts" referencing to "product" object

uglyog
2020-11-27 02:04
You might be able to do it with a recursive function

uglyog
2020-11-27 02:05
Also, the Java 8 lambda extension might also help

sushil.kumar
2020-11-27 02:06
```.minArrayLike("subProducts",0,1)```

sushil.kumar
2020-11-27 02:08
how to define/associate this recursive object relationship, are there any examples to docs

uglyog
2020-11-27 02:10
None that I know of

sushil.kumar
2020-11-27 02:11
ok, thank you for looking in to it, happy thanksgiving

zhujian
2020-11-27 07:54
has joined #pact-jvm

kjayachandra2000
2020-11-27 08:55
Hi All, when I try to refresh gradle[./gradlew clean] on a provider repo/project i am getting an error attached both the pact information and the error

uladzislau_danilchyk
2020-11-27 09:48
@uglyog, with gradle

matt.fellows
2020-11-27 09:51
is there a pact broker running on port `8113`?

matt.fellows
2020-11-27 09:51
(I?m assuming not!)

kjayachandra2000
2020-11-27 10:06
no

matt.fellows
2020-11-27 10:15
so there?s your answer

kjayachandra2000
2020-11-27 10:29
so if i want to use `./gradlew clean` i need pact broker to be running ?

matt.fellows
2020-11-27 10:36
If you want to do a provider test with Pact, you have to either a) point to a running pact broker to fetch the contracts or b) have them locally

matt.fellows
2020-11-27 10:36
99.99% of the time it should be a broker

matt.fellows
2020-11-27 10:37
and 99.99% of the time, the broker shouldn?t be running on your machine

matt.fellows
2020-11-27 10:37
it is a shared piece of infrastructure that all of your team/company uses

kjayachandra2000
2020-11-27 10:38
thanks matt, is my configuration correct for provider?

kjayachandra2000
2020-11-27 10:38
which i have shared in the screenshot

h.octavian
2020-11-27 14:08
has joined #pact-jvm

h.octavian
2020-11-27 14:11
Hi all, do you have a Java code example on how to use pact-jvm for consumer and provider tests of a message queue (I use RabbitMQ) ?

nathan.deamer
2020-11-27 16:35
End of Day Friday in the UK and struggling with the DSL to match this: ```{ "references": { "Key1": [ "123456789" ], "Key2": [ "three-random-words" ] } }``` In Java: `Map<String, List<String>> references;` Can anyone help please :slightly_smiling_face:

matt.fellows
2020-11-27 22:02
pactflowexamples


matt.fellows
2020-11-27 22:03
There's at least one Java Kafka example there. The principle is the same for all message queues

noel
2020-11-28 23:12
has joined #pact-jvm

uglyog
2020-11-29 00:14
You need to wrap the pact broker section in a if statement so it is not executed all the time. See the section in https://github.com/pact-foundation/pact-jvm/tree/master/provider/gradle#for-pact-jvm-versions-before-410

uglyog
2020-11-29 00:17
Are they JUnit tests?

uglyog
2020-11-29 00:19
If so, you can add a SLF4J library to the classpath (like logback). If you're using Spring (or Springboot), you need to configure it as per the Spring instructions.

noel
2020-11-29 01:24
I'm in a situation where each service is built once and deployed into multiple environments where some endpoints are only enabled in specific environments. Each dev/test environment will have its own broker. I'd like to conditionally enable/disable certain consumer pact tests and attempted to use the junit `EnabledIfEnvironmentVariable` annotation but pact-jvm doesn't like skipped tests without being completely `Disabled` : https://github.com/pact-foundation/pact-jvm/blob/1bb705c13e140e621d482e3240a89f7121fbdd63/consumer/junit5/src/main/kotlin/au/com/dius/pact/consumer/junit5/PactConsumerTestExt.kt#L423 Is there another approach to conditionally enable tests so pacts could differ on a per-environment basis? Thanks!

uglyog
2020-11-29 01:44
Pact is designed to verify what is running matches what is in your production environment. There is no support for any type of optional validation apart from what the test frameworks give you.

matt.fellows
2020-11-29 03:42
> Each dev/test environment will have its own broker. that is really not how Pact is supposed to work. Why do you do this?

matt.fellows
2020-11-29 03:42
> Is there another approach to conditionally enable tests so pacts could differ on a per-environment basis? Thanks! tags. tags are how you differentiate the content/use of pacts e.g. `dev` or `test` or `prod`?

noel
2020-11-29 04:40
Hey guys, thanks for the feedback. To clarify, I have multiple production environments. Each production environment has its own test environment where CI takes place independently. Some service endpoints are disabled in certain prod/test environments. So a pact between two services in one environment might have a subset of the interactions of the pact between the same two services in another environment. Also, some services don't exist at all in certain prod/test environments. So that's why I've been considering one broker per test environment, to track each independently.

noel
2020-11-29 04:48
I did discover that I can annotate pact builder methods with Disabled and pact stops complaining about them not being executed if the corresponding `PactTestFor` is conditionally disabled: ```@Disabled @Pact(consumer = "A", provider = "B") public RequestResponsePact pactABxxx(PactDslWithProvider builder) { ... @EnabledIfEnvironmentVariable(named = "PARTNER_ENVIRONMENT", matches = "XXXX") @Test @PactTestFor(pactMethod = "pactABxxx") void myTestForXXXX() { ...``` And the pacts generated only include the "activated" interactions

noel
2020-11-29 05:00
Thanks for mentioning tags. :eyes: Maybe I'm way out in left field here and need to consider a different approach :joy:

matt.fellows
2020-11-29 21:12
> I have multiple production environments How many production environments?

matt.fellows
2020-11-29 21:13
Either way, your tests need to know about the environment - whether using a different broker or otherwise - so I?d suggest parameterising the builds and using tags to differentiate environments

matt.fellows
2020-11-29 21:13
multiple prod environments feels the same to me

matt.fellows
2020-11-29 21:13
Having multiple brokers mean tools like `can-i-deploy` will be hard to use effectively

matt.fellows
2020-11-29 21:14
it?s really working against the way the broker was intended to be used, so you?re up for more surprises in the future

muraalee
2020-11-30 01:56
has joined #pact-jvm

pooja.sharma
2020-11-30 08:52
has joined #pact-jvm

pooja.sharma
2020-11-30 09:06
hi All, i am new to pact testing and hoping for a little guidance, I am trying to create pactdsl body for a Json like this (screenshot), the objects under root -> customer[] are all the same kind but with different values, so i am looking to just verify the pattern for each and NOT the actual values. if any one have an example of such an implementation, that would be really helpful. thanks in advance

mo
2020-11-30 09:24
has joined #pact-jvm

matt.fellows
2020-11-30 09:33
Look for the like matchers in the docs

matt.fellows
2020-11-30 09:33
I think it's called `arraylike` or similar

uladzislau_danilchyk
2020-11-30 09:58
Hi all! Is there any way to do not fire error when state on a provider side is not defined? There are cases when Consumer defines state, e.g. "products exist" but Provider shouldn't do something special inside provider state method. But if method with `@State` is not defined it fails. How to do not fail without having `@State` ?

pooja.sharma
2020-11-30 10:06
Thanks for a quick reply Matt, will look it up

uglyog
2020-11-30 10:33
There is nothing to support that. Please raise an issue on the Github repo


uladzislau_danilchyk
2020-11-30 14:01
@uglyog, I have tried this but unfortunately...

noel
2020-11-30 15:23
Thanks Matt. Agreed. I do like the idea of instead parameterising the builds and using tags and one global broker. This way we could also fail builds for an environment if the pact tests failed for that environment.

kjayachandra2000
2020-11-30 18:33
Hey all, what's the difference between `pact-jvm-consumer-java8_2.12` and `pact-jvm-consumer-java8` most of the online examples are using java8_2.12 :thinking_face:

phil.endsley
2020-11-30 18:34
`pact-jvm-consumer-java8_2.12` is an old version. The artifacts were renamed a while ago to support java 9 modules

kjayachandra2000
2020-11-30 18:38
so I can use the latest modules if my code base is on java 8 ?

phil.endsley
2020-11-30 18:52
We do. We might be using java 11+ to run tests? It's been a while since that was setup

eric.jones
2020-11-30 21:38
has joined #pact-jvm

david.greene
2020-11-30 21:47
has joined #pact-jvm

pavel.azarau
2020-12-01 00:50
Hi folks. I?m using Gradle plugin ?http://au.com.dius.pact? version ?4.1.11" on provider side to run pacts verification. I?ve configured a web hook in Pactflow which passes 2 parameters (as Gradle plugin docs suggests https://docs.pact.io/implementation_guides/jvm/provider/gradle/#allowing-just-the-changed-pact-specified-in-a-webhook-to-be-verified-406). Those parameters are successfully picked up by CI and passed to Gradle build as: ? -Ppact.filter.consumers=<consumer_name> ? -Ppact.filter.pacturl=https://ourcompanydomain.pactflow.io/pacts/provider/provider-name/consumer/consumer-name/pact-version/pact-version/metadata/somemetadata. pactVerify task results in `WARNING: There are no consumers to verify for provider ?external-authentication-service?. ` However when I run get request with pact.filter.pacturl value I get the pact. I was testing the build locally and noticed that when I run `./gradlew pactVerify` it fetches a correct pact and verifies it. But when I run `./gradlew pactVerify -Ppact.filter.consumers=<consumer-name>` (with consumer name which was passed from Pactflow) the task results in `WARNING: There are no consumers to verify for provider ?external-authentication-service?. ` And this even without passing -Ppact.filter.pacturl. Any ideas why consumer name filtering parameter breaks filtering?

uglyog
2020-12-01 00:54
`pact.filter.pacturl` is pointing to a single pact file, so there is no need to filter by consumer name. It has only one consumer

uglyog
2020-12-01 00:55
Those two properties were never designed to be used together

pavel.azarau
2020-12-01 00:59
thanks! I?ll try using just url to filter. FYI there are 2 places in docs where it says to use those 2 filtering parameters together though (or maybe I misunderstood it) ? https://docs.pact.io/implementation_guides/jvm/provider/gradle/#project-properties , ```pact.filter.pacturl This filter allows just the just the changed pact specified in a webhook to be run. It should be used in conjunction with pact.filter.consumers``` ? https://docs.pact.io/implementation_guides/jvm/provider/gradle/#allowing-just-the-changed-pact-specified-in-a-webhook-to-be-verified-406 , see example

uglyog
2020-12-01 01:02
:thinking_face: I wonder why that is, doesn't make sense

pavel.azarau
2020-12-01 01:03
now I?ve just tried `./gradlew pactVerify -Ppact.filter.pacturl=<URL passed from Pactflow>` and got the same WARNING: There are no consumers to verify for provider ?provider name?

uglyog
2020-12-01 01:04
You will have to provide some debug logs to see what is going on

bas
2020-12-01 09:00
has joined #pact-jvm

wainstead
2020-12-01 14:57
has joined #pact-jvm

kjayachandra2000
2020-12-01 18:01
Hi All, can we run pact provider tests without running actual api service ?

pavel.azarau
2020-12-01 18:01
my Gradle plugin config contains the following ```fromPactBroker { selectors = latestTags(project.hasProperty("consumerTag") ? consumerTag : 'master') }``` I need it to be able to run verification for a build pipeline. So it?s a bit odd but I?ve made it work when I?ve replaced pact.filter.consumers to a proper consumerTag (so web hook passes a tag). I was assuming that pacturl would override `selectors` from plugin too

pavel.azarau
2020-12-01 18:05
to explain a bit more. I don?t have pacts with `master` tag in Pactfow atm. And it looks like Gradle was trying to fetch `master` pact anyway even though later (if this fetch is successful) it actually uses pact.filter.pacturl value to actually verify correct pact

pavel.azarau
2020-12-01 18:06
would like to know it too :slightly_smiling_face: I was able to do it for messages (unit test style). But I wonder if it?s possible for API

uglyog
2020-12-01 20:02
If you use unit tests

kjayachandra2000
2020-12-01 20:10
is there any example i can check on?

jerobinson
2020-12-01 20:32
has joined #pact-jvm

uglyog
2020-12-01 22:41
The spring boot examples can verify just the controllers, not the full service. If you're using Springboot, look at https://github.com/pact-foundation/pact-jvm/tree/master/provider/spring

sumedhagamage
2020-12-02 03:33
has joined #pact-jvm

sumedhagamage
2020-12-02 04:16
qq on test scope It says recommend to use Consumer ClientApi class unit test. What is the rational behind not to use Pact in consumer behavior test. For example if we use SpringBootTest to run consumer IT test that touch consumer MVC + Service and persistence (with H2) and use Pact for external API calls.

sumedhagamage
2020-12-02 04:21
I get that we should not use to test Provider behavior. But some cases we need to test consumer behavior based on different response from provider. I think exact like Provider states. So if we want to use Pact as part of Consumer behavior test. What would be the solution.

sumedhagamage
2020-12-02 04:23
Like if @State -> Student count > 1 consumer have different business logic and if @State Student count =0 consumer have different business logic

abubics
2020-12-02 04:25
The scope you're describing is much wider than the contract at the network boundary. Blending those concerns doesn't give you specificity or isolation, and having more moving parts in the same test makes them slower and probably flakier :slightly_smiling_face:

abubics
2020-12-02 04:25
Just beat you to it, @phil.endsley :sweat_smile: I was looking forward to your input :pray:

phil.endsley
2020-12-02 04:26
Those scenarios should still be tested, but the business logic isn't part of the contract between the consumer and provider, so like @abubics said, out of the intended scope for pact

sumedhagamage
2020-12-02 04:27
Then only way to test the consumer business logic to use mock for external API calls. And have isolated unit test to ClientAPI class with Pact

abubics
2020-12-02 04:28
we must have some diagrams for this . . . I don't know how to find them

phil.endsley
2020-12-02 04:28
The scope of tests was talked about in the recent meetup, which was recorded. There were some diagrams in it

sumedhagamage
2020-12-02 04:28
but isn't that can break the contract when we mock this external calls when doing behavior testing. Because we can have false mock in place for those behavior test

sumedhagamage
2020-12-02 04:29
do you have the link for the recorded session

sumedhagamage
2020-12-02 04:29
@phil.endsley do you have the link for the recorded session


abubics
2020-12-02 04:32
As with the testing pyramid, you always need a balance of different kinds of tests, to make sure things don't work only in isolation (for example). Depending on the language and architecture, there may be different strategies to make sure that test data doesn't get out of sync. It's not a major concern of Pact, but the community often has interesting ideas about it :)

abubics
2020-12-02 04:34
e.g. if you have statically typed models, then Pact can make sure they (un)marshall properly. If you specify fixtures that are parsed into those models, then their values should be valid for all places they're used in.

abubics
2020-12-02 04:35
e.g. pact-js has a feature to extract json without Pact matchers in it, for use in non-Pact tests.

abubics
2020-12-02 04:35
it really depends on the platforms & usage patterns

phil.endsley
2020-12-02 04:36
Your business logic isn't really dependent on the contract though right? It's dependent on the response from the external api. And when you're writing tests on the consumer, you're always in control of that data. I guess your concern is that you have to remember to use the same kind of data in both pact tests and other unit tests

phil.endsley
2020-12-02 04:37
In that case, you could write test models that are shared/reused if you wanted to. There's probably a lot of different ways to solve it, each with their own pros and cons

phil.endsley
2020-12-02 04:38
I.e. what @abubics said :laughing:

sumedhagamage
2020-12-02 04:41
Yeah I think this is the concern. Yeah business logic does not depends on the contract but on the data that consumer test has the control.

sumedhagamage
2020-12-02 04:42
I think as you described share the test data models. with pact and behavior test

sumedhagamage
2020-12-02 04:50
Yeah that make sense now. Share the data models with Pact and other test, One more q. Can I pass a json or data model(lets says shared data model) to PactDsl and get type matcher other than constructing matcher through Dsl builder? Sometime the request/response can be lengthy

abubics
2020-12-02 04:56
I haven't seen this feature in any of the implementations. It's usually easier to go the other way, i.e. start with matchers, and strip them out

sumedhagamage
2020-12-02 04:57
Does pact-jvm has this feature as pact-js that you have mentioned

abubics
2020-12-02 04:58
not that I've seen, but I haven't used pact-jvm-consumer in over a year :thinking_face:

abubics
2020-12-02 04:58
Other people may know better. I haven't seen it on a roadmap, though.

sumedhagamage
2020-12-02 04:59
:thumbsup:

sumedhagamage
2020-12-02 05:01
does pact-jvm have this feature?

bethskurrie
2020-12-02 05:29
If it doesn't, please add a feature request at http://pact.canny.io

alnasl
2020-12-02 11:06
hey, I have a problem with a pact test with one put request and one get. I'm getting a strange exception when running them together. it occurs when I execute the put request. `Software caused connection abort: recv failed executing PUT http://localhost:3003/banks/54fbe6cb-6163-4a3d-bc3c-036feb16808e` feign.RetryableException: Software caused connection abort: recv failed executing PUT http://localhost:3003/banks/54fbe6cb-6163-4a3d-bc3c-036feb16808e at feign.FeignException.errorExecuting(FeignException.java:249) at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:129) at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:89) at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:100) at com.sun.proxy.$Proxy65.updateBankConnectionByIdForUser(Unknown Source) ... Caused by: http://java.net.SocketException: Software caused connection abort: recv failed at java.base/java.net.SocketInputStream.socketRead0(Native Method) at java.base/java.net.SocketInputStream.socketRead(SocketInputStream.java:115) at java.base/java.net.SocketInputStream.read(SocketInputStream.java:168) at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140) at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:252) at java.base/java.io.BufferedInputStream.read1(BufferedInputStream.java:292) at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:351) at java.base/sun.net.http://www.http.HttpClient.parseHTTPHeader(HttpClient.java:746) at java.base/sun.net.http://www.http.HttpClient.parseHTTP(HttpClient.java:689) at java.base/sun.net.http://www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1615) at java.base/sun.net.http://www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1520) at java.base/java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:527) at feign.Client$Default.convertResponse(Client.java:108) at feign.Client$Default.execute(Client.java:104) at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:119) ... 92 more It appears that the provider is aboring the connection because of timeout or something. do you have any ideas, what might be the problem? when run separately the tests are green. so this only happen when they are run together. thanks.

alnasl
2020-12-02 11:22
the get is green when the they are run together. only the put fails.

fealaer
2020-12-02 11:40
has joined #pact-jvm

fealaer
2020-12-02 11:57
@fealaer has left the channel

alnasl
2020-12-02 12:50
is it possible that the mock server closes the connection and feign is trying to reuse already stale connection?


alnasl
2020-12-02 13:18
and `@BeforeAll` public static void setup() { System.setProperty("http.keepAlive", "false"); }

alnasl
2020-12-02 13:18
is working for me as a quick fix.

alnasl
2020-12-02 13:48
ok, this works only locally, not when we run the tests on a server. is there any way to prevent the mock server from closing the connection? My Feign uses BasicHttpClientConnectionManager so, the fix for closing idle connections is not working for me.

patrick.hendron
2020-12-02 14:44
has joined #pact-jvm

h.octavian
2020-12-02 15:55
Thank you.

lpratt
2020-12-02 18:19
has joined #pact-jvm

uglyog
2020-12-02 21:48
Try setting `http.keepAlive` in the build instead in a before in the test

sandragnzalez
2020-12-03 11:04
has joined #pact-jvm

mbieganski.infomatt
2020-12-03 13:11
Hey can consumerVersionSelectors be also used as java system properties or use pactbroker.tags?

phil.endsley
2020-12-03 14:24
Yeah, but it looks like it didn't make it into the docs :disappointed: ```VersionSelector[] consumerVersionSelectors() default @VersionSelector( tag = "${pactbroker.consumerversionselectors.tags:}", latest = "${pactbroker.consumerversionselectors.latest:}");``` So these are two separate properties that are comma delimited. The lengths must match, and the indexes are matched by position. So pactbroker.consumerversionselectors.tags={"tag1","tag3","tag2"} pactbroker.consumerversionselectors.latest={"true","true","false"} would translate to ```[ @VersionSelector(tag = "tag1", latest = "true"), @VersionSelector(tag = "tag3", latest = "true"), @VersionSelector(tag = "tag2", latest = "false") ]```

kristian
2020-12-03 14:34
has joined #pact-jvm

me1466
2020-12-03 23:42
has joined #pact-jvm

mbieganski.infomatt
2020-12-04 09:52
thanks. that's what I thought.. updating from 4.1.4 to 4.11.1 :smile: looks like below did the trick ```systemProperties.put("pactbroker.consumerversionselectors.tags", "dev,master"); systemProperties.put("pactbroker.consumerversionselectors.latest", "true,true");```

mbieganski.infomatt
2020-12-04 11:13
@uglyog is there a way to to include fallback or it will work as using tags. if no tag found basically ignore?

wenfeng.li
2020-12-04 11:42
has joined #pact-jvm

lalexander2810
2020-12-04 14:53
Hey everyone. I am want to have a verification on the provider side where the validation checks type matching. As it stands currently my test also checks for data values (in Java). I've seen documentation for type matching in Ruby and wanted to implement that for Java but having some difficulty doing so. In the thread I will provide a sample json request and response.

lalexander2810
2020-12-04 15:03
Request ```{ "highlight": true, "Id": 1, "items": [ "chair" ], "offset": 0, "stats": true, "count": 5, "countEnabled": true }``` Response: ``` { "offset": 0, "total": 100, "itemStats": { "stats": { "1": 66, "2": 47, "3": 26, "4": 65, "5": 29 } } }``` So the goal is have an expected response to verify the keys and not include the values as values will change day to day.


lalexander2810
2020-12-04 15:23
@antonello I have but unfortunately when I implement, when I don't specify a value i.e. numberType value it defaults to 100 thus causing the the test to fail due to the changing in `itemStats` and `total`

antonello
2020-12-04 15:24
can you share your implementation please?

kjayachandra2000
2020-12-04 15:47
Hi All, at the provide side in gradle what should be status url ```BaseProviderTest > Pact between BusServiceNewClient (1.0-SNAPSHOT) and BusService FAILED java.lang.AssertionError at PactJUnit5VerificationProvider.kt:323 Caused by: au.com.dius.pact.provider.junitsupport.MissingStateChangeMethod at PactJUnit5VerificationProvider.kt:381 2020-12-04 16:46:10.934 INFO 18253 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'```

cdambo
2020-12-05 11:59
has joined #pact-jvm

kjayachandra2000
2020-12-07 09:34
Hi lads, this is my provider side gradle config ```pact{ broker { pactBrokerUrl = 'http://localhost:80' } serviceProviders { BusService { fromPactBroker { selectors = latestTags('test') } } } reports { defaultReports() // adds the standard console output markdown // report in markdown format json // report in json format } }``` When I try to run the tests `./gradlew pactVerify` I am running to an error as below ```Failures: 1) Verifying a pact between Pact between BusServiceNewClient (1.0-SNAPSHOT) and BusService 1.1) Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused) 1.2) Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)``` I am using springboot test to run the provider tests ```@Provider("BusService") @PactBroker(host = "localhost", port = "80") @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class BaseProviderTest {```

matt.fellows
2020-12-07 11:19
I think (I could be wrong) that because you?re running the `pactVerify` via gradle, the spring boot annotations don?t take effect

matt.fellows
2020-12-07 11:19
so either a) use the standard test phase or b) find another way to start the provider before your gradle verification task



ranjanayush03
2020-12-07 12:36
Hi all we are facing an issue when trying to validate the last login date of the user onto the app , we need to validate only the format of the time and not the actual value and we tried doing that but facing issue like '''[{mismatch=Expected '2020-12-07T11:08:54.800+00:00' to match a timestamp of 'yyyy-MM-dd'T'HH:mm:ssXx': Unable to parse the date 2020-12-07T11:08:54.800+00:00, diff=}]

ranjanayush03
2020-12-07 12:39
Can someone please help me with this..

rodrigo.costa20
2020-12-07 17:42
.

rodrigo.costa20
2020-12-07 17:43
Hello I'm creating some tests with Pact, and I'm getting this exception PactMismatchesException: The following requests were not received: This is my method to create the pact ```@Override protected RequestResponsePact createPact(PactDslWithProvider builder) { PactDslJsonBody body = new PactDslJsonBody() .stringType("firstName") .stringType("lastName") .numberType("age") .object("ids", new PactDslJsonBody() .integerType("id") .uuid("uuid") ); return builder.uponReceiving("can get user data from user data provider") .path("/user") .method("GET") .willRespondWith() .status(200) .body(body) .toPact(); }``` Does anyone know what I can be doing wrong?

phil.endsley
2020-12-07 17:54
Do you have a unit test that makes a call to the endpoint you're creating the pact for? In order to generate the contract, your consumer must prove that it's making the call you define in your contract

rodrigo.costa20
2020-12-07 18:18
Hi @phil.endsley! Yes, I do. I've created a dummy test just to see if it works, but I keep getting the error this is the test: ```@Override protected void runTest(MockServer mockServer) { assertTrue(1 == 1); }```

phil.endsley
2020-12-07 18:22
In the test, you need to make a GET call to /user with the body you defined The exception you're getting means you defined an interaction between the consumer and provider, but your consumer didn't call the endpoint in your test. Pact won't generate the contract unless your consumer makes the calls you say it will

rodrigo.costa20
2020-12-07 18:31
thanks @phil.endsley! I will try

phil.endsley
2020-12-07 18:32
:thumbsup: `mockServer` should have methods to get the base url

rodrigo.costa20
2020-12-07 18:33
I've just tried in a very basic way

rodrigo.costa20
2020-12-07 18:33
but I dont think it was enough

rodrigo.costa20
2020-12-07 18:34
I've made the call

rodrigo.costa20
2020-12-07 18:34
```System.out.println(mockServer.getUrl() + "/user");```

phil.endsley
2020-12-07 18:38
That will just print it out. You need to use some kind of http client. Ideally, you will just call the method from your code base that makes this call. Pseudo-code: Don't copy/paste :slightly_smiling_face: ```public class UserService { public UserService(url) { this.url = url; } public User getUser() { http.get(url); // http here would be an http client from whatever library you want OkHttp, RestTemplate, etc... } }``` Then in your test, you would do something like ```@Test public void testName() { User user = new UserService(mockServer.getUrl()).getUser(); // Then assert on User to make sure it's being unmarshalled correctly }```

rodrigo.costa20
2020-12-07 18:42
Thanks!

rodrigo.costa20
2020-12-07 18:42
thank you very much!

rodrigo.costa20
2020-12-07 23:28
Hey guys, In a consumer test, which is the best way to validate if the response body of the request is correct?

antonello
2020-12-07 23:47
I don?t think you will want to validate it. If the client can deserialise the response, that would be enough.

antonello
2020-12-07 23:49
In some of our consumer tests we do something simple like ```DogOutput response = client.getDog(1); assertThat(response.getName()).isEqualTo("snoopy");```

antonello
2020-12-07 23:49
in others we simply assert ```assertThat(response).isNotNull();```

rodrigo.costa20
2020-12-08 00:02
great

rodrigo.costa20
2020-12-08 00:03
I was thinking in something like matches if the response body has the correct contract

rodrigo.costa20
2020-12-08 00:03
does that makes sense?

rodrigo.costa20
2020-12-08 00:04
I mean... assert if the pattern is correct

abubics
2020-12-08 00:04
Yeah, usually the matchers in the Pact part of the test would do most (if not all) of the validation you need

abubics
2020-12-08 00:04
and then if you need more specific matching, your test framework can finish it off (with asserts or whatever)

rodrigo.costa20
2020-12-08 00:06
thanks @abubics do you have any examples of how can I do this kind of assertion?

abubics
2020-12-08 00:06
what (unit) test framework are you using?

rodrigo.costa20
2020-12-08 00:06
JUnit


abubics
2020-12-08 00:07
howtoask

2020-12-08 00:07
Please see this page for some tips on how to ask for help to get the best response from the community https://docs.pact.io/help/how_to_ask_for_help

abubics
2020-12-08 00:08
You might mean something more specific, but I can't quite tell . . . this is a Pact support channel, not a general testing support place :slightly_smiling_face:

abubics
2020-12-08 00:08
If you're having trouble with your http client, that's a separate issue, and maybe someone can help, but we'd need more context

rodrigo.costa20
2020-12-08 00:09
great! Actually my question is more about if this kind of validation is the proper one... because most of the examples that I saw on internet, they usually did not verify if the response that was get on the consumer test was matching the contract

rodrigo.costa20
2020-12-08 00:09
So I don't know if its correct to validate it, or if it is not necessary

antonello
2020-12-08 00:10
You don?t need to verify it when you?re using a strongly typed language

rodrigo.costa20
2020-12-08 00:11
e.g. In my test what I did was to actually check if the response that I got was exactly equal the response that I want... ```assertEquals(response.getBody(), responseBody);``` However, by checking on this way, I was validating the values and not only the contract itself

antonello
2020-12-08 00:12
it is not a responsibility of a consumer test to validate the contract

antonello
2020-12-08 00:13
the purpose of the `@Test` part of a consumer test is to make sure that you?ve set up your pact expectations correctly

abubics
2020-12-08 00:14
Sounds like the distinction between checking types only vs typed values is unclear maybe? You can use Pact to assert either, and that can preclude further assertions outside of the Pact DSL (if appropriate).

rodrigo.costa20
2020-12-08 00:15
@antonello... so the verification of the contract even in this case, would be in the provider side?

antonello
2020-12-08 00:17
@rodrigo.costa20 Yes. The purpose of the consumer test is to generate a pact by simulating a call to a provider that is like the one that the consumer would make in real life

abubics
2020-12-08 00:18
This example (here https://docs.pact.io/getting_started/matching/#type-matching) has both type and value validation, if that helps: ``` body: { name: "Mary", age: Pact.like(73) }```

abubics
2020-12-08 00:19
but yes, as @antonello is helping to explain, the consumer side is just one part of the overall validation/verification

rodrigo.costa20
2020-12-08 00:19
Thanks guys! @antonello @abubics You both helped a lot!

uglyog
2020-12-08 03:59
Your actual value has milliseconds in it, you need to add that to the format

uglyog
2020-12-08 03:59
`.800` needs to be matched with `.SSS`

ranjanayush03
2020-12-08 04:08
Thank you I tried this earlier but then also it was throwin unable to parse error.

uglyog
2020-12-08 04:15
```> DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").parse('2020-12-07T11:08:54.800+00:00') ===> {OffsetSeconds=0, InstantSeconds=1607339334},ISO resolved to 2020-12-07T11:08:54.800```

uglyog
2020-12-08 04:15
`yyyy-MM-dd'T'HH:mm:ss.SSSXXX` will work

ranjanayush03
2020-12-08 04:17
Thank you will try this..

ranjanayush03
2020-12-08 04:19
Yeah it worked thank you. .

gayatree.eee
2020-12-08 04:50
has joined #pact-jvm

antonello
2020-12-08 07:58
When did the above started to happen? Just want to avoid upgrading to that version :scream:

abhi.nandan
2020-12-08 10:16
@antonello I faced this on 4.1.8

antonello
2020-12-08 10:16
Interested, I haven?t observed it on 4.1.9

rodrigo.costa20
2020-12-08 13:11
Hey guys! Just a question about best pratices... I'm creating my tests and my contracts on consumer side... and I have many situations... A contract with will responde with 200 with an especific body, another that will response 201 and will return another body, another with 404...

rodrigo.costa20
2020-12-08 13:11
I'm creating those contracts in separated classes

rodrigo.costa20
2020-12-08 13:12
which is the best way to create those contracts?

rodrigo.costa20
2020-12-08 13:12
should I do this creation on the same "builder.uponReceiving..." ?

brendan.donegan
2020-12-08 14:29
@uglyog out of curiosity is there a way to do this in pact-js?

lalexander2810
2020-12-08 15:10
@antonello Sorry about the late response my computer died on me Request ``` private static final String requestWithItem = new PactDslJsonBody() .booleanType("highlight", true) .numberType("Id", 1) .array("items") .string("chair).closeArray() .numberType("offset", 0) .booleanType("stats", true) .numberType("count", 5) .booleanType("countEnabled", true) .toString();``` Response ``` private static final String responseWithSkus = new PactDslJsonBody() .numberType("offset", 0) .numberType("total", 100) .object("ItemStats") .object("stats") .numberType("1", 66) .numberType("2", 47) .numberType("3", 26) .numberType("4", 65) .numberType("5", 29) .closeObject() .closeObject().toString();```

lalexander2810
2020-12-08 15:40
The `stats` object is dynamic and will change when the mock server is hit as the values will differ as I am trying to only test for the keys / data type.


jgfarias42
2020-12-08 16:49
_uponReceiving_ is just a name for the interaction, it doesn?t affect anything at runtime.

jgfarias42
2020-12-08 16:54
Depending on your configuration, you will run the risk of overwritting a contract. It?s safer (and more important, easier to understand) if you start with one class for each Client object / Producer you have. You then will have many sections: ? 1 - Create the mockServer ? 2 - Create the Client object ? 3 - Define one expected interaction between the Client object and the mock server ? 4 - Define a test where you call the Client object (which by itself will call the mockServer) and assert over its response; ? 5 - Repeat (3) and (4) for all expected interactions. Then you can refactor your test class to make it cleaner, if necessary.

jgfarias42
2020-12-08 17:04
[Android][JUnit] Short version: Hey folks, I?m having having troubles in figuring out if my Pact Server is receiving the calls. Is there a way to toggle some logging mechanism in the Pact Server? I?m instantiating it like this: (I can also refactor to JUnit 5 if necessary) ```@get: Rule val mockProvider = PactProviderRuleMk2( "MyProducer", "localhost", 9003, this )``` Long version: So far, on the the Android app I?m working, we were using Pact successfully via RestAssured. However, now we want to refactor it so that our tests will use the Client object that the Android app uses, thus coupling the tests to the Client objects. These Client objects use a in-house subscription mechanism to make async HTTP calls. Debugging out, I see that everything behaves as expected: The arguments for the Client object function are correct transformed in a message that the async HTTP call mechanism understands, targeting the correct URL in localhost, the message is notified to the subscribers, etc. However, neither the success or error callback functions are called after notification - the execution just keeps stuck in a limbo. I decreased the timeouts, but still stuck. If I run a cURL against _localhost_ on the expected URL, I get the response the Pact Server was configured to reply, Is there a way to turn on logs on the Pact Server, so I can investigate if the messages are arriving in the Pact Server?

sumedhagamage
2020-12-08 20:53
We had this issue. But it is related to fail-safe plugin. Not sure you are using this. Technically mvn verify should execute this Springboot test. no need pact:verify

sumedhagamage
2020-12-08 20:54
mvn verify -dpact.verify.publishResults=true

sumedhagamage
2020-12-08 20:54
pushed the verification

sumedhagamage
2020-12-08 20:54
but I think if you want to run verification against running provider you can use pact:verify

sumedhagamage
2020-12-08 20:55
in Springboot test this test will execute in verify goal and -dpact.verify.publishResults=true flag will publish the result to broker

uglyog
2020-12-08 22:09
Only with the V3 beta, it supports those matching functions

uglyog
2020-12-08 22:13
Pact-JVM uses standard SLF4J loggers, so if you have those configured and set to debug, you will get the logs.

abubics
2020-12-09 00:53
There's also usually a separate log file just for the pact mock server, it ends up in `output/pact/server.log`, or something :thinking_face:

uglyog
2020-12-09 00:54
That's the Ruby one, because it is a separate process

uglyog
2020-12-09 00:55
But with SLF4J, you can configure certain packages to log to a separate file


c.pavan1986
2020-12-09 04:18
has joined #pact-jvm

matt.fellows
2020-12-09 09:35
You may not have seen it because for most practical purposes it won't matter. The issue is just that the passing of the verification results for a failing contract doesn't report the passing interactions, just the failing ones.

matt.fellows
2020-12-09 09:36
So contract status, can-i-deploy etc will still work the same way

antonello
2020-12-09 09:36
I am a bit confused - I thought we were reporting cumulatively to the broker, not per interaction.

antonello
2020-12-09 09:50
Ok - I looked again at the issue and I can see that it is about what?s reported in the POST to the broker with the results.

antonello
2020-12-09 09:52
Aside from the incorrect behaviour, when would this ever matter? If you - for whatever reason - want to go and see the verification results in the broker to understand why a verification failed?

matt.fellows
2020-12-09 10:59
I can?t think of a reason it matters significantly, apart from maybe being a bit misleading

william.pritchard
2020-12-09 15:28
has joined #pact-jvm

parveshchaudhary111
2020-12-09 17:54
has joined #pact-jvm

w.sobasik
2020-12-10 10:39
has joined #pact-jvm

rodrigo.costa20
2020-12-10 14:08
Hey guys! I'm working on a test on provider side, that I need to dealing with authentication headers... which is the best way to work on situations like this? Do you guys have any example that you could recommend?

antonello
2020-12-10 14:31
First of all, have you read this? https://docs.pact.io/provider/handling_auth/

rodrigo.costa20
2020-12-10 14:33
Yes!

rodrigo.costa20
2020-12-10 14:33
I was looking now for some pratical examples

komeershettyvinod
2020-12-10 19:00
Hi Guys

komeershettyvinod
2020-12-10 19:01
I was able to generate a contract pact json file

komeershettyvinod
2020-12-10 19:01
But I was unable to make a success at producer side

komeershettyvinod
2020-12-10 19:01
If I see the json file and assertions all are failing at matchers and generators

komeershettyvinod
2020-12-10 19:02
So can any 1 throw some light on whats the difference between matchers and generators

komeershettyvinod
2020-12-10 19:02
?


matt.fellows
2020-12-11 05:16
there is an example of how to deal with authorization there


matt.fellows
2020-12-11 05:17
Extrapolating to Java with Request Filters is all you should need to do

kjayachandra2000
2020-12-11 08:15
Hey All, while writing consumer test which of these have to be used. ```LambdaDsl.newJsonBody((object) -> { object.stringType("station", "Hammersmith") .stringType("nr", "613"); })``` or ```new PactDslJsonArray() .array() .stringValue("a1") .stringValue("a2") .closeArray();``` my config is Java8 with consumer 4.1.11 ?

uglyog
2020-12-12 00:20
Can you please elaborate what you mean by this? Can you provide the error and logs?

uglyog
2020-12-12 00:20
You can use either. It depends on your preferences.

kjayachandra2000
2020-12-12 10:36
thanks, which one of this advised to use

thanuxxxx
2020-12-12 22:41
has joined #pact-jvm

uglyog
2020-12-13 02:40
There is no one advised over the other. It is a matter of style. Do you prefer the older Java only code, or the newer one using lambdas?

ian.hamilton
2020-12-13 06:53
has joined #pact-jvm

colm.j.murphy91
2020-12-13 07:02
has joined #pact-jvm

victoria.kruczek
2020-12-13 14:13
has joined #pact-jvm

komeershettyvinod
2020-12-13 18:18
java.lang.AssertionError: 0 - BodyComparisonResult(mismatches={$.marketingPlanObjective.launchDate=[BodyMismatch(expected="2000-01-31T18:30:00Z", actual="2022-11-12T18:30:00Z", mismatch=Expected "2022-11-12T18:30:00Z" to match a timestamp of 'yyyy-MM-dd'T'HH:mm:sss': Unable to parse the date: 2022-11-12T18:30:00Z

komeershettyvinod
2020-12-13 18:18
Getting Above error even though it has matching date format

komeershettyvinod
2020-12-13 18:19
In Client side code declared as:

komeershettyvinod
2020-12-13 18:19
```launchDate(timestamp)```

wuddarwin
2020-12-14 05:23
has joined #pact-jvm

uglyog
2020-12-14 09:27
The format is wrong, it should end with `:ss`

connor.aird
2020-12-14 15:52
has joined #pact-jvm

arman.najafian
2020-12-14 15:52
has joined #pact-jvm

praveen.lakkaraju
2020-12-14 16:12
has joined #pact-jvm

alejandro.germain
2020-12-14 16:26
has joined #pact-jvm

komeershettyvinod
2020-12-14 16:35
Hi In my pact.json file I want the request pattern something like below ``` "description": "marketingplan details", "request": { "method": "GET", "generators": { "path": { "type": "ProviderState", "expression": "api/v1/marketingPlanDetails/${uuid}", "dataType": "STRING" } } },``` But it always generates as below - ```"description": "marketingplan details", "request": { "method": "GET", "path": "/api/v1/marketingPlanDetails/5f591924089d2c4fdc64e0bd" },``` Any reason why I could not generate the generators and path object (with type, expression and datatype)attributes, My groovy client code is below: ```given('test Get call marketing plan details') uponReceiving('marketingplan details') // upon_receiving starts a new interaction withAttributes( method: 'get', path: fromProviderState('/api/v1/marketingPlanDetails/${uuid}','/api/v1/marketingPlanDetails/5f591924089d2c4fdc64e0bd') ) willRespondWith( // define the response we want returned status: 200, headers: ['Content-Type': 'application/json'])```

komeershettyvinod
2020-12-14 16:39
can any 1 please help me out

phil.endsley
2020-12-14 17:50
If you're not overriding the `${uuid}` parameter in the state changed method, it will use the default path you provided. It looks like that's what's happening. https://docs.pact.io/implementation_guides/jvm/provider/gradle#returning-values-that-can-be-injected Your state change method needs to return a map/dictionary where `uuid` is the key, and the path value you want to substitute is the value

komeershettyvinod
2020-12-14 18:17
@phil.endsley This is nothing to do with at provider side, If I manually update the .json file to the one which I showed above its working fine at provider side, But I am not sure what changes to do in consumer code to make it generated automatically

phil.endsley
2020-12-14 18:21
Oh, sorry for the misunderstanding. Not sure then, what you have matches the examples in the docs...I'm not a groovy user, so I don't have direct experience. What version of pact are you using? If it's 3.6.11+, I'm not sure...

komeershettyvinod
2020-12-14 18:23
@phil.endsley ``` I am using below versions, testCompile 'au.com.dius:pact-jvm-consumer-groovy_2.12:3.6.11' testCompile 'au.com.dius:pact-jvm-consumer-junit_2.12:3.6.11'```

komeershettyvinod
2020-12-14 18:25
I do not see in the documentation though


phil.endsley
2020-12-14 18:30
The first suggestion you'll probably get will be to update versions and see if that fixes it. Could be a bug in an older version. The package structure changed since the version you're using https://mvnrepository.com/artifact/au.com.dius.pact.consumer/groovy https://mvnrepository.com/artifact/au.com.dius.pact.consumer/junit

komeershettyvinod
2020-12-14 19:07
I am not sure changing the version will work, anyways will try it, but changing the version will break my existing scripts :disappointed:

komeershettyvinod
2020-12-14 19:07
?

komeershettyvinod
2020-12-14 19:23
Also do we have any documentation for the latest pact versions?

rodrigo.costa20
2020-12-14 19:45
Hey guys! Does anyone here have already done any kind of integration using pact and jersey tests? I'm having some issues with it

phil.endsley
2020-12-14 19:49
Not sure if it will break existing scripts. The API is the same with newer versions, but the package names changed. I believe everything in http://docs.pact.io should be for the latest version, unless otherwise specified

phil.endsley
2020-12-14 19:50
I've done this. What issues are you having?

rodrigo.costa20
2020-12-14 20:18
I need to set the application target using Jest, and I'm on pact provider side, so I also need to set the pact target... so when I try to set the jersey target I get a nullpointerexception

rodrigo.costa20
2020-12-14 20:18
how can I set the application target for both of them?

rodrigo.costa20
2020-12-14 20:46
jersey uses a WebTarget

rodrigo.costa20
2020-12-14 20:46
pact use HttpTestTarget

phil.endsley
2020-12-14 20:53
I'm a little lost. `HttpTestTarget` is what pact uses to make the request defined in the contract against a running instance of the provider. So it needs to be configured with the host/port that your service is accessible from in your test. Jersey's `WebTarget` is used to make outbound requests, right? Are you doing that in your provider tests? We do not do that. We do configure them for our consumer tests though

rodrigo.costa20
2020-12-14 20:56
In the project that I'm working we are using jersey to perform requests... and as jersey has a testcontainer, jersey also starts my application properly with it. In pact, I need to start my application using jersey context, and also jersey will start the container... however, I'm a little lost on how can I use the jersey context and start my application and how can pact understand that I'm using jersey

phil.endsley
2020-12-14 21:07
Pact's HttpTestTarget doesn't have an impact on starting your application. This is just telling Pact where your application is during the test. > as jersey has a testcontainer, jersey also starts my application properly with it. If you're using testcontainers, and you have a way to start your application with it, that certainly seems like a valid way to do your test. You would just need to start your application's container during the setup of your test. > how can pact understand that I'm using jersey Why does it need to know? Pact, and any other system making calls into your application, shouldn't care what framework or tech stack you're using. That's essentially an implementation detail that shouldn't impact how your services are invoked.

phil.endsley
2020-12-14 21:07
If you're running a container for your provider tests, Pact's `HttpTestTarget` would just need to be configured with that container's host and port

rodrigo.costa20
2020-12-14 21:11
Yes, the problem is that I need to mock some integration... and when I start my container manually, I'm not able to change the integration, so I cannot use the mock

rodrigo.costa20
2020-12-14 21:12
If I start my application with jersey, I would be able to change the behaviour of my app when starting, and I could use my mock properly

rodrigo.costa20
2020-12-14 21:14
actually I was trying to find a solution to mock a integration that I have... but I did not find a solution yet, since, the way that we start the application we start it already pointing to the real integration, so we were not able to mock this integration in runtime

phil.endsley
2020-12-14 21:20
Sure. Not sure if I can help there. We use Grizzly with Guice to start a webserver in the test context and bind mocks with Guice instead of our real integration points. Not sure if that helps or not

rodrigo.costa20
2020-12-14 21:22
great! thanks a lot

rodrigo.costa20
2020-12-14 21:23
do you have any code example of jersey and pact being used together that you can show? I did not find any example

kjayachandra2000
2020-12-14 21:39
Hey all, any help on this, i am getting an error while running the consumer test

phil.endsley
2020-12-14 21:54
Sure. I'm still a little confused, because like I said, Pact doesn't care about what framework you use. It sounds like it's how you're standing up your jersey services within your tests ``` @BeforeAll public static void setUpClass() throws Exception { // Setup server GrizzlyWebServer webServer = new GrizzlyWebServer(PORT); ServletAdapter adapter = new ServletAdapter(); adapter.addServletListener(ContextListener.class.getName()); adapter.addFilter(new GuiceFilter(), "guiceFilter", null); webServer.addGrizzlyAdapter(adapter, null); webServer.start(); } @BeforeEach public void setUp(PactVerificationContext context) { context.setTarget(new HttpTestTarget("localhost", PORT, "/")); // Other setup, mocks, etc... } // .. // .. public static final class ContextListener extends GuiceServletContextListener { @Override protected Injector getInjector() { return Guice.createInjector( new JerseyConfigModule(), // This has something like serve("/*").with(GuiceContainer.class, params); in it // Other Guice modules.. }```

phil.endsley
2020-12-14 21:55
Don't focus on getting Pact working with Jersey, try to find out how to get your application stood up in your test context. Once you do that, Pact just needs the host and port it's running on


matt.fellows
2020-12-14 23:17
:point_up:

matt.fellows
2020-12-14 23:18
@phil.endsley thanks for all of your question answering. It really is much appreciated. I woke up one morning last week only to see the most thorough explanation of the pending / WIP pacts workflow I?d seen - I think only Beth knows more than you. :taco: :taco: :taco:

rodrigo.costa20
2020-12-15 01:16
Thank you very much @phil.endsley You helped me a lot

josh.ellinger
2020-12-15 01:22
has joined #pact-jvm


nikitsenka
2020-12-15 09:35
has joined #pact-jvm

nikitsenka
2020-12-15 09:39
Created Java 15 + Webflux pact consumer-provider example using latest versions. Just for testing and upgrade https://github.com/nikitsenka/pact-contracts

hibahawes
2020-12-15 09:53
has joined #pact-jvm

sarvar
2020-12-15 14:24
has joined #pact-jvm

komeershettyvinod
2020-12-15 16:09
With the latest upgrade issue has been Fixed But I came across couple of issues

komeershettyvinod
2020-12-15 16:10
1. kotlin error which got resolved by adding an extra dependency "compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: '1.4.20'"

komeershettyvinod
2020-12-15 16:10
But could not resolve the second issue

komeershettyvinod
2020-12-15 16:11
consumer code is failing at line ```assert result == PactVerificationResult.OK.INSTANCE // This means it is all good``` with below message groovy.lang.MissingPropertyException: No such property: OK for class: http://au.com.dius.pact.consumer.PactVerificationResult

komeershettyvinod
2020-12-15 16:11
can any 1 help this?

suruchipatidar14
2020-12-16 05:35
has joined #pact-jvm

smatheson
2020-12-16 06:33
has joined #pact-jvm

olayemifolakemi
2020-12-16 15:23
has joined #pact-jvm

ania.kovalchuk
2020-12-17 00:09
has joined #pact-jvm

writetojoshma
2020-12-17 05:52
has joined #pact-jvm

yann.courtel
2020-12-17 09:43
Hey guys, we have a problem when using MockMvcTarget to mock our API with the pact version 3.6.xx I had to downgrade to 3.5.24 to be able to mock my external APIs. Anyone had this issue before? Is there a different mechanism to mock the APIs after the 3.6.xx version? Thanks a lot.

rejeesh.g
2020-12-17 11:07
has joined #pact-jvm

gayatree.eee
2020-12-17 11:19
~Can you please help us how to enable log for pending pact console output for pact JVM~

lukas.kempec
2020-12-17 12:45
has joined #pact-jvm

vikas543
2020-12-17 16:28
has joined #pact-jvm

bpugh
2020-12-17 17:05
has joined #pact-jvm

rodrigo.costa20
2020-12-17 19:12
Hi All, I know this is probably not a pact issue, but I'm getting an UnfinishedStubbingException when I mock method to be able to run my pact test properly... This is the code: ``` Invoker invoker = mock(Invoker.class); HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); Abcd abcd = mock(Abcd.class); MyRepository myRepository = mock(MyRepository.class); @BeforeEach void before(PactVerificationContext context) { doAnswer((invocation) -> { XptoClassOutputBoundary test = invocation.getArgumentAt(1, XptoClassOutputBoundary.class); test.getResponse().setValue(new BigDecimal("500")); return null; } ).when(myRepository).execute(any(), any());``` Does anyone of you have already had this problem or know what can be wrong in this code? If so, could you help me with it? Thanks!

jeff.burmood
2020-12-19 17:45
has joined #pact-jvm

kyle.florence
2020-12-19 19:21
has joined #pact-jvm

ankurmalik22
2020-12-19 21:14
has joined #pact-jvm

vsukumaran
2020-12-20 01:56
has joined #pact-jvm

omer.morad
2020-12-20 08:10
has joined #pact-jvm

ringo
2020-12-20 10:51
has joined #pact-jvm

rodrigo.costa20
2020-12-20 14:31
Hello all, I'm working on some provider tests, and the tests are all working properly, except for the case that the value that I set on provider states aparently are not being read... when I need to change the value of some state I'm having to do it directly on the Testtemplate... so my code now is like this: ```@TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void testTemplate(Pact pact, Interaction interaction, HttpRequest request, PactVerificationContext context) { http://LOGGER.info("testTemplate called: " + pact.getProvider().getName() + ", " + interaction.getDescription()); if(interaction.toString().contains("mySate01")){ // SET MOCK CHANGES``` And for some reason, if I put the same mock changes on the state method, it does not work... Do you guys know what I can be doing wrong? This is an example of a state method ```@State("myState01") public void validInteraction() { http://LOGGER.info("Now service in myState01"); }```

omer.moradd
2020-12-20 18:01
has joined #pact-jvm

uglyog
2020-12-20 22:13
You need to find out what UnfinishedStubbingException means. A quick google turned up this https://medium.com/@adamspeakman/mockito-unfinishedstubbingexception-in-tests-3d622532d491


uglyog
2020-12-20 22:24
Those tests the state annotated methods get called

mamtha.3687
2020-12-21 06:38
Hello, We're trying to explore opportunities in automating provider and consumer tests generation based on a given yaml file. We understand that it may not be possible to get to the granular level of assertions/rules that the consumer might be interested in, but the idea is to get them started with a skeletal structure so they can focus on only what is more important to them. Any thoughts or links to resources of something similar?

yann.courtel
2020-12-21 08:22
I'd say unless your assets are automatically generated, I would not recommend that. Even if you were to have contracts close to what you want, the cost of maintenance will be higher. You will most likely not know what the PACTs are containing. Although just having a structure to indicate which interactions to write might not be a bad idea.

mamtha.3687
2020-12-21 09:21
@yann.courtel agree with you on the fact that we'll not know what the PACTs contain. In spring cloud contract, we're able to generate the tests automatically using groovy files for each interaction. More than anything, it simplifies the process of specifying what you want to test and not having to know the code intricacies. Ultimate need for us is to look at automating maximum part of it to help teams onboard easily and handle most of the initial setup so it is faster too.

yann.courtel
2020-12-21 09:44
Good to know. I specialized in the .NET implementation of it but it's good to know you have that tool in hand!

mamtha.3687
2020-12-21 09:52
Oh! No it doesn't solve our problem :grin:. My bad. I assumed you had java background and spoke about Spring. Are you saying that you have implemented the interactions structure in the .net framework? Can you please share a link to your github page if it's publicly available?

yann.courtel
2020-12-21 09:56
No I meant I didn't know Java offered that. I am familiar with PACT in Spring. And no, in .NET so far there is no such thing I know of. We are at the moment trying to get in sync with the 3.0 specifications so having a tool doing to testing structure for the interactions will come later. I'll keep in mind what you are doing as it is similar to another subject we have which is to know interactions between all the consumers and providers to have an "endpoint coverage". Similar to what you want but solved differently!

souravsen1
2020-12-21 11:28
has joined #pact-jvm

kjayachandra2000
2020-12-21 13:35
Hi All, while trying to run pact provider test. I have gradle config as below ```task contractTest(type: Test) { System.setProperty 'pactbroker.host', 'localhost' System.setProperty 'pactbroker.port', '80' filter { includeTestsMatching "*ContractTest" } useJUnitPlatform() }``` but still the test fails due to `Invalid pact broker host specified ('${pactbroker.host:}'). Please provide a valid host or specify the system property 'pactbroker.host'.` my test looking something like below ```@AutoConfigureWireMock(port = 8090) @ExtendWith(SpringExtension.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD) @ActiveProfiles(Profiles.TEST) @PactBroker @Provider("FeatureToggle") public class SampleContractTest{ ...... }```

andoni.arroyo
2020-12-21 17:51
has joined #pact-jvm

mikahchapman
2020-12-21 18:53
How are you supposed to specify a x-www-form-urlencoded body where the order is not fixed? For example, we're trying to write a request that has a body like `userId=1234&value=1&value=2&value=3`, but the order of the value params is not guaranteed by the client making the request. We tried a `PactDslRootValue.stringMatcher()` with a RegEx, but that didn't quite work.


uglyog
2020-12-21 21:53
Also, if you are using static host, you can also set it on the annotation `@PactBroker(host=...`

uglyog
2020-12-21 21:54
Can you raise an issue for that, it has never been implemented

kjayachandra2000
2020-12-21 22:08
Thanks uglyog, systemProperty worked for me :party_parrot:


matt.fellows
2020-12-22 05:39
Probably about time I gave @uglyog a :taco:

theovanessen
2020-12-22 10:47
has joined #pact-jvm

stuart3166
2020-12-22 12:35
has joined #pact-jvm

kjayachandra2000
2020-12-22 14:31
Hi All, i am running the *pact provider tests* in *gradle - junit 5*, while executing the tests testcasename is displayed as `pactVerificationTestTemplate`. This might be junit5 issue but if any of you know on the fix please share I saw a something in related to this on github, but the fix was more on surefire plugin. This creating confusion on the test readability

thanuxxxx
2020-12-22 18:39
Hi all, I am trying follow this example. I have this maven dependency ``` <dependency> <groupId>au.com.dius.pact.provider</groupId> <artifactId>spring</artifactId> <version>4.1.12</version> </dependency>``` And my base class start with following ```@TestPropertySource(locations = "classpath:application-pact-test.properties") @RunWith(SpringRestPactRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @Provider("Service") @PactBroker(scheme = "https", host = "${pactbroker.host}") public abstract class PactTestContext {....}``` All I have configure my host name in application-pact-test.properties but when I run this, I am getting `java.lang.IllegalArgumentException: Invalid pact broker host specified ('${pactbroker.host}'). Please provide a valid host or specify the system property 'pactbroker.host'.` I can create system property variables and assign values but I want to put all of my values into `application-pact-test.properties` file. Am I missing anything?

uglyog
2020-12-22 22:14
Not much we can do about that, it is not a Pact issue. Your test runner is using the classname and not the test description.

uglyog
2020-12-22 22:15
Try upgrading either JUnit5 ot Gradle, my test project generates the report with the description

uglyog
2020-12-22 22:49
Where have you created the application-pact-test.properties file? It needs to be in the test resources for Springboot to pick it up.

winfante
2020-12-22 22:51
has joined #pact-jvm

thanuxxxx
2020-12-22 22:53
Springboot is actually picking up the file because, I am using some hardcoded values for testing

uglyog
2020-12-22 23:04
And if you add them to the application.properties file above that one?

thanuxxxx
2020-12-22 23:07
I didn't try to add them to the application.properties because I explicitly says to get `application-pact-test.properties`

thanuxxxx
2020-12-22 23:07
```@TestPropertySource(locations = "classpath:application-pact-test.properties") @RunWith(SpringRestPactRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @Provider("Service") @PactBroker(scheme = "https", host = "${pactbroker.host}") public abstract class PactTestContext {....}```

uglyog
2020-12-22 23:08
I'm trying to work out where your issue is. If you put the values in application.properties and it works, the issue is with the `@TestPropertySource` annotation. If it still does not work, then it is something else.


thanuxxxx
2020-12-22 23:13
I moved those variables to application.properties file and commented out @TestProperySource annotation but I see the same error. Don't you guys have an example with application.properties instead application.yml.

uglyog
2020-12-22 23:15
application.properties is functionally the same as application.yml, you can use them interchangeably

uglyog
2020-12-22 23:16
Are you using JUnit5?

uglyog
2020-12-22 23:16
No, you are using the JUnit4 runner

thanuxxxx
2020-12-22 23:17
I wanted to use JUnit5 but `@ExtendWith(SprintRestPactRunner.class)` gives syntax error

uglyog
2020-12-22 23:18
Maybe it's the abstract base class that is cauding the issue. Could you try putting the annotations on an actual test class?

thanuxxxx
2020-12-22 23:24
I did that, but now I see a different error ```java.lang.Exception: Exactly one pact source should be set, found 2: @au.com.dius.pact.provider.junitsupport.loader.PactSource(au.com.dius.pact.provider.junitsupport.loader.PactBrokerLoader.class), @au.com.dius.pact.provider.junitsupport.loader.PactSource(au.com.dius.pact.provider.junitsupport.loader.PactBrokerLoader.class) at org.junit.runners.model.InitializationError.<init>(InitializationError.java:38) at au.com.dius.pact.provider.junit.PactRunner.getPactSource(PactRunner.kt:164) at au.com.dius.pact.provider.spring.SpringRestPactRunner.getPactSource(SpringRestPactRunner.kt:60) at au.com.dius.pact.provider.junit.PactRunner.initialize(PactRunner.kt:94) at au.com.dius.pact.provider.junit.PactRunner.getChildren(PactRunner.kt:151) at org.junit.runners.ParentRunner.getFilteredChildren(ParentRunner.java:534) at org.junit.runners.ParentRunner.getDescription(ParentRunner.java:400) at org.junit.runners.model.RunnerBuilder.configureRunner(RunnerBuilder.java:81) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:72) at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:37) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70) at org.junit.internal.requests.ClassRequest.createRunner(ClassRequest.java:28) at org.junit.internal.requests.MemoizingRequest.getRunner(MemoizingRequest.java:19) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:50) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)```

uglyog
2020-12-22 23:27
Just comment out the one on the base class for now

thanuxxxx
2020-12-22 23:30
No luck. Same error `Invalid pact broker host specified ('${pactbroker.host}'). Please provide a valid host or specify the system property 'pactbroker.host'.`

thanuxxxx
2020-12-22 23:31
Let me convert my .properties file to .yml and try again

uglyog
2020-12-22 23:31
That probably won't change anything

uglyog
2020-12-22 23:32
Just to double check, the property in the property file is `pactbroker.host`?

thanuxxxx
2020-12-22 23:33
I copied from here

uglyog
2020-12-22 23:35
I mean, not what the property is, but that the property in the property file is the same as the one used on the annotation?

thanuxxxx
2020-12-22 23:41
I doubled checked they are same. Only different between the one example you shared with me and mine is extension of application. file

uglyog
2020-12-22 23:42
What version of Springboot are you using?

thanuxxxx
2020-12-22 23:43
``` Running Spring Boot (v2.3.3.RELEASE)```

souravsen1
2020-12-23 06:02
Hi I'm new to Contract tests and I'm doing a POC using Pact JVM for a client. So I'm having some difficulties setting up the pact folder. I tried declaring it under @Test @PactVerification block of the consumer side and setting the system properties for pact.rootDir location, it didn't work. Then I used maven surefire plugin and declared the pact directory from the pom file. Still it didn't work. I'm using the example from here https://m.youtube.com/watch?v=F-IUh0M-pu8&t=915s and this is his repo https://github.com/mattiasmgn/Pact-JVM-Example though his code is outdated and with some changes I'm able to run the Junit test under consumer side and it passes but dont generate any pact file. Any help on this would be highly appreciated.


souravsen1
2020-12-23 06:28
Thanks @uglyog. Will give it a check.

lars.bonnes
2020-12-23 13:05
has joined #pact-jvm

lars.bonnes
2020-12-23 13:07
Hi, I am playing around with pact over XMas and was trying out the example junit5 code provided https://docs.pact.io/implementation_guides/jvm/provider/junit5. So having a super simple example ```@ExtendWith(SpringExtension.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @Provider("GreetingsProvider") @PactFolder("pacts") public class GreetingsProviderPactTest { @TestTemplate @ExtendWith(PactVerificationSpringProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); } }``` That yields ```At least one pact source must be present on the test class java.lang.UnsupportedOperationException: At least one pact source must be present on the test class``` when executing the test. Is there something super obvious I am missing?

kjayachandra2000
2020-12-23 13:19
```@Provider("BusService") @PactBroker(host = "pact_broker_app", port = "80") @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class BaseProviderTest { @LocalServerPort private int port; @BeforeAll static void enablePublishingPact() { System.setProperty("pact.verifier.publishResults", "true"); } @BeforeEach void before(PactVerificationContext context) { context.setTarget(new HttpTestTarget("localhost", port)); } @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); } @State("With missing node in the response body") public void toDefaultNNState() { } }``` This is my provide side test and in your test you are missing the `state`

lars.bonnes
2020-12-23 13:21
What has the state to do with the pact source?


lars.bonnes
2020-12-23 13:59
True, but how is that related to the error message I am seeing? https://docs.pact.io/implementation_guides/jvm/provider/junit5spring also does not state the need to specify a state

lars.bonnes
2020-12-23 13:59
So what are you aiming at?

phil.endsley
2020-12-23 13:59
@lars.bonnes make sure you're importing the right `@PactFolder` annotation. ```import au.com.dius.pact.provider.junitsupport.loader.PactFolder;``` This has bitten people before. Unfortunate naming conflict

lars.bonnes
2020-12-23 14:04
@phil.endsley awesome. That was it. You know how they say: There are only two hard things in Computer Science: cache invalidation and naming things.

thanuxxxx
2020-12-23 16:50
Is that any other way to assign `pactbroker.host` and `token` inside my test class instead of `@PactBroker(scheme = "https", host = "${pactbroker.host}", authentication = @PactBrokerAuth(token = "${pactbroker.auth.token}"))`

thanuxxxx
2020-12-23 16:51
Even I tried something like this but it did not work ``` @BeforeClass public static void loadPactProperties() { System.setProperty("pactbroker.host","myhost"); System.setProperty("pactbroker.auth.token","mytoken"); System.setProperty("pact.verifier.publishResults", "true"); }```

uglyog
2020-12-23 22:54
These properties work for a lot of people, so you need to work out what is different with your setup. Can you clone that example repo and try running the test there?

thanuxxxx
2020-12-24 00:30
It seems like I am unable to do `@ExtendWith(SpringRestPactRunner.class)`. Can I use JUnit 5 with SpringRestPactRunner?


thanuxxxx
2020-12-24 00:36
Okay, but If I want to do this `@PactBroker(scheme = "https", host = "${pactbroker.host}", authentication = @PactBrokerAuth(token = "${pactbroker.auth.token}"))` along with Junit5 then, which maven I should use? ``` <dependency> <groupId>au.com.dius.pact.provider</groupId> <artifactId>junit5</artifactId> <version>4.1.12</version> <scope>runtime</scope> </dependency>``` Can I use above dependency?

uglyog
2020-12-24 00:37
No, read the docs at the link I posted above

thanuxxxx
2020-12-24 00:37
Okay. Let me let me read it. Thanks

thanuxxxx
2020-12-24 01:06
Okay, I redid everything with Junit5 + SpringBoot, but I am getting a similar error j`ava.lang.RuntimeException: Could not resolve property "pactbroker.host" in the system properties or environment variables and no default value is supplied`

uglyog
2020-12-24 01:07
How are you running the test?

uglyog
2020-12-24 01:08
Have you tried cloning the example project and running that?

thanuxxxx
2020-12-24 02:32
I cloned `https://github.com/pact-foundation/pact-jvm` project and did the same thing as I did for my project. I get the same error

uglyog
2020-12-24 02:50
Change that test with `PactVerificationSpringProvider` instead of `PactVerificationInvocationContextProvider` ``` @TestTemplate @ExtendWith(PactVerificationSpringProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { }``` and the values resolve for me

thanuxxxx
2020-12-24 02:51
Okay. That makes sense

thanuxxxx
2020-12-24 02:52
I think that would solve my problem as well

thanuxxxx
2020-12-24 02:52
Thank you so much

eungjun.yi
2020-12-25 14:25
has joined #pact-jvm

abhi.nandan
2020-12-27 09:50
hey, I am trying to ignore no pacts to verify by annotating the test class as `@IgnoreNoPactsToVerify(ignoreIoErrors = "${pact.verification.ignoreIoErrors:true}")` , when running the test, it is failing with the error -

abhi.nandan
2020-12-27 09:50
```au.com.dius.pact.core.pactbroker.NotFoundHalResponse: No HAL document found at path '<domain>/pacts/provider/<service-name>/for-verification' at au.com.dius.pact.core.pactbroker.HalClient.handleHalResponse(HalClient.kt:298) at au.com.dius.pact.core.pactbroker.HalClient.access$handleHalResponse(HalClient.kt:140) at au.com.dius.pact.core.pactbroker.HalClient$postJson$3.invoke(HalClient.kt:473) at au.com.dius.pact.core.pactbroker.HalClient$postJson$3.invoke(HalClient.kt:140) at au.com.dius.pact.core.support.KotlinLanguageSupportKt.handleWith(KotlinLanguageSupport.kt:38) at au.com.dius.pact.core.pactbroker.HalClient.postJson(HalClient.kt:471) at au.com.dius.pact.core.pactbroker.PactBrokerClient$fetchPactsUsingNewEndpoint$1.invoke(PactBrokerClient.kt:248) at au.com.dius.pact.core.pactbroker.PactBrokerClient$fetchPactsUsingNewEndpoint$1.invoke(PactBrokerClient.kt:138) at au.com.dius.pact.core.support.KotlinLanguageSupportKt.handleWith(KotlinLanguageSupport.kt:38) at au.com.dius.pact.core.pactbroker.PactBrokerClient.fetchPactsUsingNewEndpoint(PactBrokerClient.kt:247) at au.com.dius.pact.core.pactbroker.PactBrokerClient.fetchConsumersWithSelectors(PactBrokerClient.kt:214) at au.com.dius.pact.provider.junitsupport.loader.PactBrokerLoader.loadPactsForProvider(PactBrokerLoader.kt:209) at au.com.dius.pact.provider.junitsupport.loader.PactBrokerLoader.load(PactBrokerLoader.kt:111) at au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider$resolvePactSources$$inlined$flatMap$lambda$1.invoke(PactJUnit5VerificationProvider.kt:77) at au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider$resolvePactSources$$inlined$flatMap$lambda$1.invoke(PactJUnit5VerificationProvider.kt:34) at au.com.dius.pact.core.support.KotlinLanguageSupportKt.handleWith(KotlinLanguageSupport.kt:38) at au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider.resolvePactSources(PactJUnit5VerificationProvider.kt:77) at au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider.provideTestTemplateInvocationContexts(PactJUnit5VerificationProvider.kt:38) at org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor.lambda$execute$0(TestTemplateTestDescriptor.java:103) at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:271) at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497) at org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor.execute(TestTemplateTestDescriptor.java:107) at org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor.execute(TestTemplateTestDescriptor.java:42) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84) at java.base/java.util.ArrayList.forEach(ArrayList.java:1541) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84) at java.base/java.util.ArrayList.forEach(ArrayList.java:1541) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57) at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)```

abhi.nandan
2020-12-27 09:50
My provider test class looks as below - ```@Provider("skeleton-service") @PactBroker( host = "<host_name>", port = "443", scheme = "https", authentication = @PactBrokerAuth(token = "<pact_broker_token>"), providerTags = { "dev" } ) @IgnoreNoPactsToVerify(ignoreIoErrors = "${pact.verification.ignoreIoErrors:true}") public class MyServiceProviderContractTest { @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); } @BeforeEach void before(PactVerificationContext context) { context.setTarget(new HttpTestTarget("localhost", 7771, "/")); System.setProperty("pact.verifier.publishResults", "true"); System.setProperty("pact.provider.version", "v1"); } }```

ebanster
2020-12-27 13:18
has joined #pact-jvm

onur.baskirt
2020-12-28 10:48
has joined #pact-jvm

abhi.nandan
2020-12-28 12:04
Is there a way to convert a spring-cloud-contract to pact dsl?

uglyog
2020-12-28 22:52
If you asking about an automatic one, I haven't heard of any


massimo.daros
2020-12-29 13:18
has joined #pact-jvm

chris.fullinwider
2020-12-29 18:15
has joined #pact-jvm

piotr.soltysiak
2020-12-30 16:55
has joined #pact-jvm

piotr.soltysiak
2020-12-30 17:07
Hi all! I'm very happy to start working with pact-broker and pact-jvm, but I have little trouble with properly setting it up correctly. I have the broker up and running on non-root path (`https://api.gw.url/path/to/broker`) which causes an error while trying to test the provider: ```java.lang.IllegalArgumentException: Invalid pact broker host specified ('api.gw.url/path/to/broker'). Please provide a valid host or specify the system property 'pactbroker.host'.``` Is there a way to provide the path to broker? Or should I host the broker on subdomain? (`https://pact-broker.api.gw.url` ) Cheers!

uglyog
2020-12-30 23:06
Could you raise an issue for that?

piotr.soltysiak
2020-12-31 08:03
https://github.com/pact-foundation/pact-jvm/issues/1282 raised with more detailed description

adrian.przybyla
2021-01-04 13:41
has joined #pact-jvm

dcorrales
2021-01-04 22:06
has joined #pact-jvm

jokubas.lekevicius
2021-01-04 22:10
has joined #pact-jvm

matt195
2021-01-05 16:35
has joined #pact-jvm

rafael.manzoni
2021-01-05 17:56
has joined #pact-jvm

animesh2712
2021-01-05 19:29
has joined #pact-jvm

info
2021-01-06 01:55
has joined #pact-jvm

pascal.libenzi
2021-01-06 10:57
has joined #pact-jvm

pascal.libenzi
2021-01-06 11:03
Hello all, and happy new year! I would like to use junit5spring plugin (version 4.1.9) for testing my provider with a pact broker which is behind an ingress controller with a path (https://example.com/pact-broker). It seems that it does not work when using @PactBroker annotation since we don't have pactBrokerUrl anymore, but host, port and scheme only (path param is missing...). Do you know if a workaround exists? I didn't find any trick in the documentation of the plugin for such configuration Thank you very much

brett
2021-01-06 18:55
has joined #pact-jvm

josh.rosenfeld
2021-01-06 19:39
has joined #pact-jvm

josh.rosenfeld
2021-01-06 19:56
Hi there! Wasn't able to find any documented support so I figured I'd ask here. I'm writing a contract test for an endpoint that prepends their json payload with four characters. (So think `{"name": "Joe"}` becomes `{}__{"name": "Joe"}`). This makes it hard to both write the contract and verify it. The verification fails because it is unable to parse the response as JSON and there is a similar issue writing the contract in the first place unless we, of course, omit those first four characters. Is there any way we can equip Pact with some way of filtering out these characters before trying to match the response? Or is there perhaps some way we can test for this unconventional response body?


uglyog
2021-01-06 23:02
Unfortunately, the payload is expected to be a valid JSON document. There is no mechanism to modify the response, so you might have to look at using something like Nginx to act as a proxy.

josh.rosenfeld
2021-01-06 23:03
Alright, good to know I didn't miss anything. Thanks for the response.

pascal.libenzi
2021-01-07 08:48
Yes I saw it after, but I can?t delete my post on slack :disappointed:

pascal.libenzi
2021-01-07 08:48
thank you for the notice by the way

carlo
2021-01-07 13:24
has joined #pact-jvm

danny.porrello
2021-01-07 16:48
has joined #pact-jvm

dawood.abbas
2021-01-08 07:00
has joined #pact-jvm

souravsen1
2021-01-10 12:55
Can anyone link me to a simple Pact-jvm example project using maven for simple consumer and provider services? I'm new to Pact and contract tests, so could really use some help on this. Thanks in advance.

souravsen1
2021-01-10 13:15
Any simple maven springboot example project using pact-jvm would work.

victoria.kruczek
2021-01-10 16:35
@victoria.kruczek has left the channel

cksharma122
2021-01-10 17:19
has joined #pact-jvm

cksharma122
2021-01-10 17:20
Hi I recently created a project to learn pact testing e2e flow. In my existing project we used to have build.gradle file in which config was simple to me ```pact { publish { pactBrokerUrl = 'http://localhost:80/' } }``` In my new project I'm having build.gradle.kts file and in which if I define the same thing I gets errors. I want to know, how can I define same thing in my build.gradle.kts file?

matt.fellows
2021-01-10 20:05
Seems more like a gradle question to me.

matt.fellows
2021-01-10 20:05
Or a Kotlin one

matt.fellows
2021-01-10 20:05
What specifically stops working?

caiquedpfc
2021-01-11 04:05
has joined #pact-jvm

henrik.rudstrom
2021-01-11 18:30
has joined #pact-jvm

eric
2021-01-12 10:23
has joined #pact-jvm

eric
2021-01-12 10:37
hi - can you please advise how to inject a request body using pact-jvm ? in the consumer: `body(PactDslRootValue.valueFromProviderState("key", "example value")` in the producer: `@State...` `public Map<String,Object> mymethod() {` `map.put("key","some test value")` `returm map;` `}` I would expect the "key" string to be replaced by "some test value" when running the test but this is not happening.. any idea what goes wrong or how to debug this ?

fnguyen
2021-01-13 00:39
has joined #pact-jvm

pollet_22
2021-01-13 16:04
has joined #pact-jvm

dshattuck
2021-01-13 20:49
has joined #pact-jvm

thomas.rosati
2021-01-13 21:58
has joined #pact-jvm

ranjanayush03
2021-01-14 07:43
Hi all I am facing an issue that upon matching on an API which accepts some query parameters, while writing consumer test then the interactions with query parameters embedded directly in the url are considered non-matching whereas when I seperate out the query as "match query" then it is working fine so is there any way so that I can specify the parameters inside the path itself..

uglyog
2021-01-14 07:47
If "match query" is working, why would you want to include it in the path?

ranjanayush03
2021-01-14 07:52
Actually we have a requirement where we are autogenerating the consumer side test cases and finding it difficult to includeit in the parameters inside match query so we thought of doing it in the path itself but it was failing there..

ranjanayush03
2021-01-14 07:53
So is there a way to include it in path itself .

uglyog
2021-01-14 07:53
If you put it in the path, it needs to match exactly

ranjanayush03
2021-01-14 07:54
Okay if I provide the exact path in the interaction builder then it will pass

ranjanayush03
2021-01-14 07:55
I tried matching it exactly but it failed when i tried running the test cases.

rahulsmalpani
2021-01-14 07:56
has joined #pact-jvm

uglyog
2021-01-14 07:59
It is intended to use the query parameter attributes, not the path. That is not supported, and matches won't work

ranjanayush03
2021-01-14 08:02
Okay so if i have an end point like "api/users?id=2" then I need to provide the "id" inside query param or will .path("api/users?id=2") work.?

uglyog
2021-01-14 08:04
`.path("api/users").query("id=2")`

ranjanayush03
2021-01-14 08:07
Thank you will try this...

sacha.camfferman768
2021-01-14 09:42
has joined #pact-jvm

brandonbeard86
2021-01-14 22:10
has joined #pact-jvm

geetishnayak
2021-01-15 01:02
has joined #pact-jvm

shettyg
2021-01-15 14:18
has joined #pact-jvm

shettyg
2021-01-15 14:22
Hi All.I am facing an error while implementing pact provider using Junit

shettyg
2021-01-15 14:22
Receiver class http://au.com.dius.pact.provider.spring.junit5.MockMvcTestTarget does not define or inherit an implementation of the resolved method 'abstract java.util.Map executeInteraction(java.lang.Object, java.lang.Object)' of interface http://au.com.dius.pact.provider.junit5.TestTarget. java.lang.AbstractMethodError: Receiver class http://au.com.dius.pact.provider.spring.junit5.MockMvcTestTarget does not define or inherit an implementation of the resolved method 'abstract java.util.Map executeInteraction(java.lang.Object, java.lang.Object)' of interface http://au.com.dius.pact.provider.junit5.TestTarget. Has anyone faced this error before

shettyg
2021-01-15 14:23
Has anyone faced this error before

phil.endsley
2021-01-15 14:29
What version are you using? Do you paste an example (redacted if necessary) of your current setup? Did you see the docs that have an example? https://docs.pact.io/implementation_guides/jvm/provider/junit5spring#usage at the very bottom

shettyg
2021-01-15 14:32
Yes I referred to the document and implemented the provider

shettyg
2021-01-15 14:32
```public class ContractVerificationTest { @Autowired private MockMvc mockMvc; @MockBean private MongoTemplate mongoTemplate; @MockBean private RestTemplateBuilder restTemplateBuilder; @MockBean private FeatureTogglesClient featureTogglesClient; @MockBean private RestTemplate restTemplate; @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); } @BeforeEach void before(PactVerificationContext context) { context.setTarget(new MockMvcTestTarget(mockMvc)); } @State("treatments exist") public void txMetadataExists() { // nothing to do, real service is used } }```

shettyg
2021-01-15 14:33
Its giving me response back

shettyg
2021-01-15 14:33
but in context.verifyInteraction(); its failing

shettyg
2021-01-15 14:34
```testCompile('au.com.dius:pact-jvm-provider-junit5:4.0.10') testCompile('au.com.dius.pact.provider:junit5spring:4.1.7')```

shettyg
2021-01-15 14:34
these are the versions I am using

phil.endsley
2021-01-15 14:50
I'm pretty sure this is because you have conflicting versions. I'm not sure if you need both of those dependencies or not. You could try commenting out the pact-jvm-provider-junit5 one. If you do need both, make them both the same version. The api was changed between those two versions 4.0.10: ```fun executeInteraction(client: Any?, request: Any?): Map<String, Any>``` 4.1.7 ```fun executeInteraction(client: Any?, request: Any?): ProviderResponse```

shettyg
2021-01-15 15:15
```testCompile('au.com.dius:pact-jvm-provider-junit5:4.0.10')``` Then these annotations are not working MockMvcTestTarget and State

phil.endsley
2021-01-15 15:16
Keep both if you need them, but you should use the same version across all the pact libraries. So they should both be 4.0.10 or 4.1.7

shettyg
2021-01-15 15:24
Do we have a 4.1.7 version for the below one

shettyg
2021-01-15 15:24
```testCompile('au.com.dius:pact-jvm-provider-junit5:4.0.10')```

phil.endsley
2021-01-15 15:26
> Then these annotations are not working MockMvcTestTarget and State They don't work, or you can't import them?

shettyg
2021-01-15 15:28
Can Import them but trying to compile it doesnt work

shettyg
2021-01-15 15:28
compile

natarajang1
2021-01-15 15:29
has joined #pact-jvm

shettyg
2021-01-15 15:30
If we use testCompile or TestImplementation the jars are not pulled properly

phil.endsley
2021-01-15 15:32
Hmm...well, I know there was a change a while ago where the packages were reorganized and new jars were produced. I think that was 4.0 -> 4.1, but I'm not 100% sure... I know `@State` was changed. At least, the package is different. In 4.1.7, it should be ```import au.com.dius.pact.provider.junitsupport.State;``` We don't use mockmvc, but `testCompile('au.com.dius.pact.provider:junit5spring:4.1.7')` works fine for us and everything we use.

shettyg
2021-01-15 15:40
Even if I keep the testCompile('au.com.dius.pact.provider:junit5spring:4.1.7') on build the gradle file it gives following error

shettyg
2021-01-15 15:40
error: package http://au.com.dius.pact.provider.junit5 does not exist import http://au.com.dius.pact.provider.junit5.PactVerificationContext; ^

phil.endsley
2021-01-15 15:47
It gets pulled in for us...idk The line above is the only pact dependency that's explicitly included, and it pulls in everything else we need.

natarajang1
2021-01-16 00:36
@phil.endsley i'm getting the below error even though host, port and protocol values are configured in application.yaml file. Invalid pact broker host specified ('${pactbroker.host:}'). Please provide a valid host or specify the system property 'pactbroker.host'.

bheemreddy181
2021-01-17 03:57
has joined #pact-jvm

bheemreddy181
2021-01-17 04:00
Team , I am using workshop implementation to run some quick tests using java , seeing below exceptions on step 1 ```2021-01-16T21:59:30.771-0600 [DEBUG] [org.gradle.internal.work.DefaultWorkerLeaseService] Worker lease root.1 completed (0 worker(s) in use) 2021-01-16T21:59:30.771-0600 [DEBUG] [org.gradle.internal.resources.AbstractTrackedResourceLock] Daemon worker Thread 7: released lock on root.1 2021-01-16T21:59:30.771-0600 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 2021-01-16T21:59:30.771-0600 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception. 2021-01-16T21:59:30.771-0600 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 2021-01-16T21:59:30.771-0600 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Where: 2021-01-16T21:59:30.771-0600 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Build file '/Users/user/eclipse-workspace/pact-workshop-jvm/providers/springboot-provider/build.gradle' line: 51 2021-01-16T21:59:30.771-0600 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 2021-01-16T21:59:30.771-0600 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong: 2021-01-16T21:59:30.771-0600 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] A problem occurred evaluating project ':providers:springboot-provider'. 2021-01-16T21:59:30.772-0600 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Call to fetch pacts from Pact Broker failed with an exception 2021-01-16T21:59:30.772-0600 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 2021-01-16T21:59:30.772-0600 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Try: 2021-01-16T21:59:30.772-0600 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Run with --stacktrace option to get the stack trace. Run with --scan to get full insights. 2021-01-16T21:59:30.772-0600 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 2021-01-16T21:59:30.772-0600 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Get more help at https://help.gradle.org 2021-01-16T21:59:30.772-0600 [WARN] [org.gradle.internal.featurelifecycle.LoggingDeprecatedFeatureHandler] Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/6.6.1/userguide/command_line_interface.html#sec:command_line_warnings 2021-01-16T21:59:30.772-0600 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] 2021-01-16T21:59:30.772-0600 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] BUILD FAILED in 813ms 2021-01-16T21:59:30.772-0600 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Run build'``` I have my pact broker running locally

matt.fellows
2021-01-17 08:10
Step1 doesn't interact with the pact broker. Have you checked out the step1 branch?

matt.fellows
2021-01-17 08:12
My guess is that you've run it from `master` which is the same as being in step13, so it's trying to download non-existent pacts from the broker

matt.fellows
2021-01-17 08:13
Might need to increase logging to see actual problem tho

bheemreddy181
2021-01-17 16:53
`./gradlew consumer:run` also fails with the same error - same normal gradle build too

uglyog
2021-01-17 22:46
Please provide details on the error that occurred. See https://docs.gradle.org/current/userguide/command_line_interface.html#command_line_interface for details on running Gradle tasks. The `-s` option prints out the error stack trace.

michel.neufeglise
2021-01-18 08:55
has joined #pact-jvm

bart.boersma
2021-01-18 10:48
has joined #pact-jvm

bheemreddy181
2021-01-18 16:01
here is what i see when i run `gradle build -s` on master

uglyog
2021-01-18 22:15
We need the full stack trace. Also, you should run the Gradle tasks as specified in the readme.

matt.fellows
2021-01-19 00:00
Anyone know how to split pact JUnit tests over multiple files? I'm sure it's possible but a search of the JVM docs doesn't help https://pact-foundation.slack.com/archives/C5F4KFKR8/p1610986004015100?thread_ts=1610721992.009100&cid=C5F4KFKR8 @michaelkochub

michaelkochub
2021-01-19 00:00
has joined #pact-jvm

uglyog
2021-01-19 00:06
The tests are annotation driven. They don't have to exist in the same test class.

matt.fellows
2021-01-19 00:07
Cool, and Pact JVM will simply merge the interactions into the pact right? (assuming you don?t clear the pact file in between)

uglyog
2021-01-19 00:08
Yes, using the values from the annotations

matt.fellows
2021-01-19 00:09
too easy!

monica.wu
2021-01-19 06:25
has joined #pact-jvm

makobernal
2021-01-19 08:23
has joined #pact-jvm

makobernal
2021-01-19 08:46
Hello! I was wondering if there under Pact Provider + Junit5 it is possible to "name" the single tests being run per consumer pact being verified. For instance in my block ```@TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); }``` I end up generating test tasks with the name `pactVerificationTestTemplate(PactVerificationContext)[1]`. As oposed to `Pact between consumer-xyz(version) and provider - (pact description here)`

makobernal
2021-01-19 08:47
IntelliJ test run example.

makobernal
2021-01-19 08:50
I have other provider verification tests using JUnit4 and `@TestTarget` where this was done automatically.

jibrail.idris
2021-01-19 10:11
has joined #pact-jvm

jibrail.idris
2021-01-19 10:27
Hi, I am getting this error message. What does it mean? `No ParameterResolver registered for parameter [http://au.com.dius.pact.provider.junit5.PactVerificationContext context] in method [void ccc.xxx.SomeTest.beforeTestCase(http://au.com.dius.pact.provider.junit5.PactVerificationContext)].`

jmvb.registros
2021-01-19 11:01
has joined #pact-jvm

yann.courtel
2021-01-19 11:06
Hi everyone, we are creating a new provider class in java but the consumer is using pact-net therefore the matchers version seem to be the problem. Anyone know if there is a specific SpringBoot annotation to make this work ? Here is the error after running it locally : Diff:       {     -  "json_class": "Pact::SomethingLike",     -  "contents": {     -    "httpStatus": 400,     -    "errorMessage": "You must fill in either the customerCaseId field or the scopusId.",     -    "date": "2021-01-12T14:41:17.178878"     -  }     +  "httpStatus": 400,     +  "errorMessage": "You must fill in either the customerCaseId field or the scopusId.",     +  "date": "2021-01-19T11:46:03.691868600"     } Thanks a lot

matt.fellows
2021-01-19 11:12
hmmm that .NET contract looks broken, it shouldn?t have the `json_class` bits in it

matt.fellows
2021-01-19 11:12
it?s either a _really_ old version, or something went wrong. Could you please share the contract?

yann.courtel
2021-01-19 12:57
It's an old version. The consumer version appears to be a 1.0.0 pact spec version.

matt.fellows
2021-01-19 13:06
Any chance that can be upgraded?

matt.fellows
2021-01-19 13:33
I'm no Java expert but I'm guessing it's the wrong annotation or a missing import/dependency. Could you please share your code?

matt.fellows
2021-01-19 13:33
Howtoexamples


matt.fellows
2021-01-19 13:34
There's a couple of Java examples there for reference

yann.courtel
2021-01-19 13:58
```{ "consumer": { "name": "CancellationApi" }, "provider": { "name": "cc.action" }, "interactions": [ { "description": "A request to create an action", "request": { "method": "post", "path": "/actions", "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "customerCaseId": 2920754, "scopusId": "azerty", "customerId": "0000000NPY85", "idAction": 1, "description": "Ouverture", "userId": 4259, "txt": "txt", "message": "comment" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "json_class": "Pact::SomethingLike", "contents": { "evolId": 2 } } } } ], "metadata": { "pactSpecification": { "version": "1.0.0" } }, "createdAt": "2021-01-15T15:25:42+00:00" }```

yann.courtel
2021-01-19 13:58
for my contract... yeah ideally it would need to be upgraded I know

yann.courtel
2021-01-19 14:15
so there is no way to validate this old version of PACT with a java provider ?

uglyog
2021-01-19 22:07
Are you using Maven?

uglyog
2021-01-19 22:09
Pact-JVM supports 1.0 Pact files, but that Pact file is not correct: ```"body": { "json_class": "Pact::SomethingLike", "contents": { "evolId": 2 } }```

tpham
2021-01-19 22:36
has joined #pact-jvm

natarajang1
2021-01-20 01:07
can some please help me on this issue?

jibrail.idris
2021-01-20 01:45
@matt.fellows The issue was that the @Test and @State methods cannot co-exist in the test class if it is executed in IntelliJ (ant task). `mvn test` runs fine.


matt.fellows
2021-01-20 01:56
Makes sense. The state handler is not a test

jibrail.idris
2021-01-20 01:59
Would be awesome if this can be included in the docs. Will definitely save engineers troubleshooting time because the error is too vague.

matt.fellows
2021-01-20 02:29
Is it in the docs to say that annotation _should_ be there? The `@Test` annotation is for actual tests, right?

matt.fellows
2021-01-20 02:34
I?m not sure guarding against the use of non-Pact annotations is something Pact should be doing. In this case, it?s clearly a JUnit issue

jibrail.idris
2021-01-20 02:39
@matt.fellows In principle, yes I agree with you. Practically, at times, engineers tend to mix the two because on the surface they appear to be the same and hence the confusion, as shown in the Github issue page, which is one of some that I found on Google. In my test scenario, the pact contract testing on the provider side becomes part of the integration tests because we are using that to validate the response state. Our @State annotated methods are filled with assert() after persistence implying that @State methods also become integration tests. In theory, we can extract the two; a clean integration tests away from contract testing. However, that would mean duplicate codes across both tests and hence combining the two makes sense from the maintainability point of view.

vishal.grover
2021-01-20 03:12
has joined #pact-jvm

phil.endsley
2021-01-20 03:21
@natarajang1 you asked a new question in a thread about something else. You'd get quicker help by asking with a new post. Can you post the code you have that's running into issues too. Specifically, the annotations on the class

matt.fellows
2021-01-20 05:21
I see what you mean. Perhaps there are others who?ve tried similar things

matt.fellows
2021-01-20 05:22
I believe you could still run assertions in those state methods, just not under a separate test context - am I right in thinking that?

jibrail.idris
2021-01-20 05:43
Yes. That's correct

priya.saraf
2021-01-20 08:43
has joined #pact-jvm

fahad.aj.khan
2021-01-20 08:58
has joined #pact-jvm

fahad.aj.khan
2021-01-20 09:05
Hello... I can't get pact-jvm to write the pact files. I've debugged into PactWriter.kt (vesion 4.1.14) and can see that it is writing the file on line 99. But that file does not ever appear on my machine.

fahad.aj.khan
2021-01-20 09:31
Please ignore my message above... Our build tools is removing the file after the test run.

nicole.jaenchen
2021-01-20 09:38
has joined #pact-jvm

vuttithatkrongyot
2021-01-20 10:10
Hi Andra, how was it going on, is it work or not? I wanna use pact with cucumber too.

dinakaran.ulaganathan
2021-01-20 13:59
has joined #pact-jvm

makobernal
2021-01-20 14:29
No, gradle

antonello
2021-01-20 15:57
Same issue here

yann.courtel
2021-01-20 16:07
Hey Matt, apparently, it does work with the 2.0.0 specifications. Thanks

natarajang1
2021-01-20 17:47
sure i'll start a new post, thanks and sorry about that

alan.nichols
2021-01-20 17:57
Hi everyone. I?m working with a team that?s creating pacts from android that are using the 3.0 specification, but the provider is using .net core which only supports up to 2.0 specification at the moment. As a result there are many warnings such as > WARN: Ignoring unsupported combine AND for path $[?something?] which I think means that it?s ignoring some of the contract and we aren?t getting the full coverage that we need. If this is correct then I?ve been asked about downgrading the android contracts to 2.0 specification but from reading up on this it seems like I?d have to install a very old version that doesn?t support kotlin, and then rewrite everything. Could anyone give me (or point me to) some more info about this please?

ptsiakos77
2021-01-20 21:55
has joined #pact-jvm

abubics
2021-01-20 23:10
I feel like there's a way to limit the features to a particular version, but I don't know what it is, or where the docs are

jibrail.idris
2021-01-21 00:51
Is it possible to use @TargetRequestFilter with @SpringBootTest?

jibrail.idris
2021-01-21 00:54
Currently, I am hardcoding my Authorization: Bearer token in the pact contract file and I want to remove that and put it in the provider request header

jibrail.idris
2021-01-21 01:03
Is @TargetRequestFilter even working at all?

uglyog
2021-01-21 01:09
Yes, if you're using JUnit 4

mhdtouban
2021-01-21 01:58
has joined #pact-jvm

mhdtouban
2021-01-21 02:43
Hello guys, am starting writing pact tests for our android project and I was wondering why wouldn't the pact file be generated, am I missing something here? those pact files would be uploaded to our broker, so no need to deal with the provider locally. ```class PactTests { @Pact(provider = "public_api", consumer = "Andromeda") fun createPact(builder: PactDslWithProvider): RequestResponsePact? { return builder .given("account exists") .uponReceiving("A request for account") .path("/auth/api/v1/users/me") .method("GET") .willRespondWith() .status(200) .body("[\n" + " {\n" + " \"response\":[\n" + " {\n" + " \"id\":2920615,\n" + " \"first_name\":\"John\"\n" + " }\n" + " ]\n" + " }\n" + "]") .toPact() } @Test @PactVerification("public_api") @Throws(IOException::class) fun test() { assertThat(true, `is`(true)) } }```

uglyog
2021-01-21 02:52
Are you using Gradle or Maven? If you enable debug logs, you will see logs indicating where the file is being written to

mhdtouban
2021-01-21 02:54
am using Gradle, i don't think it's getting generated i searched for it all the place.

matt.fellows
2021-01-21 02:55
> those pact files would be uploaded to our broker, so no need to deal with the provider locally. what do you mean by that one, sorry?

mhdtouban
2021-01-21 02:56
i mean i don't need to deal with the verification part.. all what i care about is generating the pact file and then i'll upload them to our pact broker.

matt.fellows
2021-01-21 02:57
If you could share the debug logs, we migth be able to help

jibrail.idris
2021-01-21 03:11
@mhdtouban Your JSON pact files should be in the pacts/ directory.

veeraprathap.n
2021-01-21 04:10
has joined #pact-jvm

mhdtouban
2021-01-21 05:04
ok so i made the class `extends ConsumerPactTest` and now am getting the following error ```java.lang.NoClassDefFoundError: org/apache/http/conn/ssl/TrustSelfSignedStrategy```

mhdtouban
2021-01-21 05:06
i didn't build a client yet, so am wondering why am getting that

uglyog
2021-01-21 05:07
That's the Apache HTTP library, which is used by the Pact framework

uglyog
2021-01-21 05:09
You need to have `org.apache.httpcomponents:httpclient:4.5.13` on your classpath

mhdtouban
2021-01-21 05:16
alright i added the library but am still getting the error, is there something else needed to bypass that ?

uglyog
2021-01-21 05:16
Did you add it to the correct classpath? It needs to be on the test one.

mhdtouban
2021-01-21 05:26
I added to project root build.gradle inside the dependencies

uglyog
2021-01-21 05:28
Can you show us?

mhdtouban
2021-01-21 05:31
``` dependencies { classpath 'org.apache.httpcomponents:httpclient:4.5.13' }```

uglyog
2021-01-21 05:33
It needs to be `testCompile` not `classpath`

mhdtouban
2021-01-21 05:37
unfortunately still getting the error

uglyog
2021-01-21 05:41
Where is the pact-jvm dependency defined?

uglyog
2021-01-21 05:43
Android provides it's own versions of the Apache HTTP libraries, so you can't run the tests as Android tests.

uglyog
2021-01-21 05:45
What version of Pact-JVM are you using?


mhdtouban
2021-01-21 05:46
they are defined same place. ```testImplementation 'au.com.dius.pact.consumer:junit:4.1.0'``` i was using 4.1.7 but after using 4.1.0 am getting different error now ```java.lang.NoClassDefFoundError: org/apache/http/entity/ContentType```

uglyog
2021-01-21 05:49
Are you running Android instrumented tests?

mhdtouban
2021-01-21 05:51
no it's a local unit test

matt.fellows
2021-01-21 06:07
Perhaps you could share a reproducable setup that we can look at, including the commands you?re running.

matt.fellows
2021-01-21 06:07
see howtoask for more

2021-01-21 06:07
Please see this page for some tips on how to ask for help to get the best response from the community https://docs.pact.io/help/how_to_ask_for_help

gayatree.eee
2021-01-21 07:19
Tried using -Dpact.filter.consumers=conumer1 to pick only consumer1 contract while verifying Provider build. But still it picks all the contracts from all the consumer. Please help!!

uglyog
2021-01-21 07:30
How are you verifying the provider?

gayatree.eee
2021-01-21 09:23
from local using maven verify

tsiakos
2021-01-21 09:24
has joined #pact-jvm

phillip.goff
2021-01-21 09:50
has joined #pact-jvm


gayatree.eee
2021-01-21 10:17
mvn verify -Pcontract-tests -Dpact.filter.consumers=consumer1

alan.nichols
2021-01-21 10:35
Found an actual section on it in the junit docs - https://docs.pact.io/implementation_guides/jvm/consumer/junit#generating-v2-spec-pact-files This seems to fix my problem.

alan.nichols
2021-01-21 11:29
That said we?re now struggling with getting the junit pact to generate a contract with numbers having ?type? matchers rather than the v3 only int, decimal etc

alan.nichols
2021-01-21 11:39
Posting here in case it?s lost in a thread. We are trying to make v2 contracts using a new enough version of pact to support kotlin, and can choose to make the contracts in specification 2.0, however we can?t work out how to select a type match for a number. the numberType methods seem to still be generating the contract with things like decimal matcher which aren?t supported in v2. Any suggestions of how we should be writing our pact to get a matcher of just type?

matt.fellows
2021-01-21 12:33
There is an annotation/parameter from memory that lets you specify the spec version that gets spit out

matt.fellows
2021-01-21 12:34
There you go. It?s in the `@PactTestFor` annotation

kjayachandra2000
2021-01-21 12:44
```pact { publish { pactDirectory = "$buildDir/pacts" pactBrokerUrl = 'https://pact.com/' pactBrokerUsername = 'username' pactBrokerPassword = 'password' } }``` hey lads, just want to check. is there a way to publish the contract's to pact broker without adding this to `build.gradle` file? :thinking_face: something like a java method

oleg
2021-01-21 13:05
has joined #pact-jvm

alan.nichols
2021-01-21 13:41
Thanks yeah that?s what we found. But then when we run our test a contract is created with things like ```"match": "integer"``` that isn?t supported by a v2 contract and so can?t be verified. I?m wondering is we need to build up our test with a different method in the dsl but I can?t find a likely candidate

alan.nichols
2021-01-21 15:54
I?ll circle back to this when I?ve confirmed but this may have been a caching issue

uglyog
2021-01-21 22:06
No, that's the only way

mhdtouban
2021-01-22 01:30
back to this issue https://pact-foundation.slack.com/archives/C9UN99H24/p1611207961008900?thread_ts=1611196998.004300&cid=C9UN99H24 which am getting now as well, I had apache jar added as a library since Apache HTTP client is deprecateded in android and the one downloaded through gradle doesn't have ContentType class. What would be a solution here to bypass that error?

geetishnayak
2021-01-22 07:36
Hello Everyone. I have a `build.gradle` file which has the pact properties present, where I have specified the bearer token and url etc for authentication purposes. When you run `gradle build` the bearer token gets verified against the URL and if the bearer token is invalid/present there is a 401 thrown which is obvious. But the problem is I do not want this authentication check to happen during the build phase. Is there any way to disable this? Also whats the recommended way to use the bearer token without checking it in to the source-code(build.gradle) which is accessible to everyone? Can it be passed as a property during the build phase? Thanks

kjayachandra2000
2021-01-22 08:31
i think this will help you, give a try ```pact { if ('pactVerify' in gradle.startParameter.taskNames) { serviceProviders { BusService { protocol = 'http' host = 'localhost' port = 8083 hasPactsFromPactBroker("http://localhost:80") } } } }```

geetishnayak
2021-01-22 08:50
Super. That worked. Thanks

matt.fellows
2021-01-22 08:52
:taco: for @kjayachandra2000, thanks!

gayatree.eee
2021-01-22 09:47
mvn pact:verify is throwing 404 for the contract tests added for spring boot based provider. The tests are being verified successfully when ran as a junit from the test class. Please advice

thomas.powell
2021-01-22 10:18
has joined #pact-jvm

wesleythomaswilliams
2021-01-22 10:33
Not sure if this is useful for your case, but we also test spring boot providers and we don't use pact:verify. Our jenkins pipeline executes the provider tests as part of our unit tests `mvn test` and we pass in `-Dpact.verifier.publishResults=true` to publish the results.

gayatree.eee
2021-01-22 10:35
Thanks for the quick reply. We are using pact:verify as we need to pass pact.filter.consumers as a plugin paramter

jibrail.idris
2021-01-22 11:51
@uglyog thanks

shettyg
2021-01-22 16:16
Hi All, I am trying to implement PACT Consumer in java using junit5. I am referring to the pact documentation using junit and junit5. Under juint we have ConsumerCLient and we have a separate Pact Consumer provided. So if I want to implement consumer using junit5 then what are the steps to follow. If I could get the step by step process would be better. Thanks

wesleythomaswilliams
2021-01-22 16:40
Are you using Maven to import dependencies etc?

shettyg
2021-01-22 16:42
yeah I am using maven

shettyg
2021-01-22 16:44
```@ExtendWith(PactConsumerTestExt.class) @PactTestFor(providerName = "treatments-metadata-api") public class ExampleJavaConsumerPactTest { @Pact(provider="treatments-metadata-api", consumer="hemocare-portal-api") public RequestResponsePact createPact(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("ExampleJavaConsumerPactTest test interaction") .path("/articles.json") .method("GET") .willRespondWith() .status(200) .body("{\"responsetest\": true}") .toPact(); } protected void runTest(MockServer mockServer, PactTestExecutionContext context) throws IOException { Assert.assertEquals(new ConsumerClient(mockServer.getUrl()).options("/second"), 200); Map expectedResponse = new HashMap(); expectedResponse.put("responsetest", true); expectedResponse.put("name", "harry"); assertEquals(new ConsumerClient(mockServer.getUrl()).getAsMap("/", ""), expectedResponse); assertEquals(new ConsumerClient(mockServer.getUrl()).options("/second"), 200); } @Test void test(MockServer mockServer) throws IOException { HttpResponse httpResponse = Request.Get(mockServer.getUrl() + "/articles.json").execute().returnResponse(); assertThat(httpResponse.getStatusLine().getStatusCode(), is(equalTo(200))); }```

shettyg
2021-01-22 16:45
This is what I have using juint and junit5 as per the pact document...not sure how to implement ConsumerClient

wesleythomaswilliams
2021-01-22 16:49
Have you looked at this example: https://github.com/pact-foundation/pact-jvm/blob/master/consumer/junit5/src/test/java/au/com/dius/pact/consumer/junit5/ArticlesTest.java I'm not sure about the need for the runTest method you have there.

shettyg
2021-01-22 16:56
It was present in the pact documentation using juint...but will not include it..Thanks

stefan.selent
2021-01-23 01:54
has joined #pact-jvm

natarajang1
2021-01-24 04:06
i'm trying to set tag and version of consumerVersionSelectors on provider thru system properties variable "pactbroker.consumerversionselectors.tags" instead of adding that in @PactBroker annotation. I want this to be dynamic based on the git branch for which the CI/CD build runs. I'm doing it in the code via. prop.put("pactbroker.consumerversionselectors.tags", patcTag); on @BeforeEach method but its seems to be not working.

uglyog
2021-01-24 04:09
It would be better to pass those values in from your CI build instead of doing it in code

natarajang1
2021-01-24 04:15
but how to set those values thru the build? sorry i'm not clear yet. Pact provider test cases will run as junit5 on spring MockMvcTarget

uglyog
2021-01-24 04:23
In the CI, it will probably have a build script that starts the Java test process.

natarajang1
2021-01-24 04:27
but do i need to use "pactbroker.consumerversionselectors.tags" to set the tag value?>

uglyog
2021-01-24 04:33
Yes, they can be set as an environment variable or as a system property for the test process (which is different to set depending on using Gradle or Maven)

natarajang1
2021-01-24 04:42
i tried passing it as -Dpactbroker.consumerversionselectors.tags=dev but its not getting set.

uglyog
2021-01-24 04:44
Because it needs to be set on the test process, not the Maven process. The build starts Maven, which starts a new JVM process to run the tests. They need to be set on *that* process.


natarajang1
2021-01-24 04:46
i'm currently running the test on Intellij (junit) and passing the above value in VM options

uglyog
2021-01-24 04:48
In that case, you need to use the JUnit test runner, not the Maven one

uglyog
2021-01-24 04:51
You can also set it as an environment variable

natarajang1
2021-01-24 04:52
let me try

natarajang1
2021-01-24 05:17
sorry my bad , i was running as gradle test not junit. so what i did is added VM options -Dpactbroker.consumerversionselectors.tags=local and in build.gradle > test i added ```systemProperty 'pactbroker.consumerversionselectors.tags', System.getProperty("pactbroker.consumerversionselectors.tags")``` now i can see this value populated in system.properties inside provider test class ```@BeforeEach void before(PactVerificationContext context) { Properties prop = System.getProperties(); }```

natarajang1
2021-01-24 05:18
but still it's not pulling the correct tag that i'm passing


natarajang1
2021-01-24 05:22
[from Pact Broker http://host:9092/pacts/provider/<consumer-name>/consumer/<provider-name>version/e66b9ef (Tag local)] ---- i see this in the console, so its pulling the correct tag i believe but when it publishes the results to broker i see other tags getting updated as well, any idea why this is happening?

uglyog
2021-01-24 05:29
Because all those tags refer to the same version of the Pact

mhdtouban
2021-01-24 05:32
hey @uglyog any workaround for the issue above?

natarajang1
2021-01-24 05:36
versions (gitsha) are different and here is the screenshot from broker UI. Since i'm running the test in local i'm expecting only "local" tag to get updated but not "feature". i cropped the consumer name and provider name for security reasons

uglyog
2021-01-24 05:38
Check the Pact that those tags point to, If it has the same contents, it has the same version

uglyog
2021-01-24 05:38
Has the Pact changed between local and feature?

natarajang1
2021-01-24 05:39
nope, its the same

uglyog
2021-01-24 05:44
Sorry, I'm not an Android developer, so I haven't heard of a fix for this issue.

uglyog
2021-01-24 05:44
One way would be to run the tests as normal java tests, and not include any Android libs

uglyog
2021-01-24 05:45
Or exclude the Apache HTTP client from the Android libs

mhdtouban
2021-01-24 06:14
that's the thing, am running those as a unit tests without android interference.

uglyog
2021-01-24 06:20
But your build has the wrong version of the Apache HTTP client on the classpath, you need to work out why.

uglyog
2021-01-24 06:22
Try running `./gradlew dependencies` on your project and have a look at all the test dependencies

uglyog
2021-01-24 06:23
Also look at all the plugins you are using. Some plugins (like Spring) can alter the dependencies

mhdtouban
2021-01-24 06:34
right, seems we weren't getting the correct version of the Apache HTTP. the issue is solved now. thanks

uglyog
2021-01-24 06:44
Can you add a comment to the issue on how you resolved the issue?

kjayachandra2000
2021-01-25 07:04
I am using something like this, you can replace the tags with environment variables. You can give a try with the below code ```pact { publish { pactDirectory = "$buildDir/pacts" pactBrokerUrl = 'http://pact_broker_app:80' tags = ["test","prod"] } }```

c.pavan1986
2021-01-25 11:22
On using the pactbroker.consumers in @PactBroker annotation, its giving runtime error

c.pavan1986
2021-01-25 11:22
org.junit.runners.model.InitializationError

c.pavan1986
2021-01-25 11:27
On using the pactbroker.consumers in @PactBroker annotation, its giving runtime error org.junit.runners.model.InitializationError


paulo
2021-01-25 11:37
has joined #pact-jvm

c.pavan1986
2021-01-25 12:03
Looks like pactbroker.consumers is deprecated, but how do we configure it from system properties if we have to use consumerVersionSelectors, https://github.com/pact-foundation/pact-jvm/commit/677cc2d2575ad25a4ed5a9036bca9c2c6e999c3c


natarajang1
2021-01-25 13:35
sure thanks

natarajang1
2021-01-25 14:07
I tried setting it as system property pact.provider.tag to local but still seeing the same issue. Here is the screen shot

kmckeever
2021-01-25 14:38
has joined #pact-jvm

mhdtouban
2021-01-25 15:27
sure, ill

mhdtouban
2021-01-25 16:18
done

robert.land
2021-01-25 19:25
has joined #pact-jvm

aparnachaudhari
2021-01-25 21:34
has joined #pact-jvm

uglyog
2021-01-25 22:39
Please provide the runtime error and stack trace so we can try help you

uglyog
2021-01-25 22:41
That is not deprecated. Where did you get the idea that that was so?

uglyog
2021-01-25 22:45
It is because it is the same Pact file, so all the tags and verification results are applied to it. If in your branch, if you published a Pact with changed contents, you will see the tag and results only apply to the new one.

gwhill7
2021-01-25 23:23
has joined #pact-jvm

ruben.cagnie
2021-01-26 00:16
I'm trying to write a test class where I want to setup my contracts in the function that is annotated with `@Pact` , but has multiple `@Test` for each endpoint. The problem I am running into that every test fails because not all contracts are exercised in that test - `The following requests were not received` . Is there a way or will I have to (a) make 1 Test class per endpoint or (2) combine all my tests into 1 `@Test`?

uglyog
2021-01-26 00:19
Define separate `@Pact` methods for each test that only have the expectations for that test.


ruben.cagnie
2021-01-26 00:40
Thanks for the quick reply @uglyog. That seems to do exactly what I was looking for, thanks!

ruben.cagnie
2021-01-26 00:40
I do have some weird behavior, that if I test 1 contract, it works fine, but if I have the same test with other contract tests, it starts failing

uglyog
2021-01-26 00:43
Can you provide the error?

ruben.cagnie
2021-01-26 00:47
Looking into the logs, it looks like the wrong method is called

ruben.cagnie
2021-01-26 00:47
So the outline of my functions: ``` @Pact(consumer="xxx") fun setupTransactionPacts(builder: PactDslWithProvider): RequestResponsePact { @Pact(consumer="xxx") fun setupCreateAccountPacts(builder: PactDslWithProvider): RequestResponsePact { @Test @PactVerification(fragment = "setupCreateAccountPacts") fun testCreateAccount(mockServer: MockServer) { @Test @PactVerification(fragment = "setupTransactionPacts") fun testTransactions(mockServer: MockServer) {```

ruben.cagnie
2021-01-26 00:48
But for the `testTransactions` , I get the following in the logs: ```Invoking method 'setupCreateAccountPacts' to get Pact for the test 'testTransactions'```

ruben.cagnie
2021-01-26 00:57
I found it. I was stepping through the code and apparently the annotation to be used is ```@PactTestFor(pactMethod = "setupTransactionPacts") ```

uglyog
2021-01-26 01:07
Ah, you're using JUnit 5

natarajang1
2021-01-26 01:49
@uglyog Yes, feature and local has the same contract. Let me explain what i'm trying to achieve here. I'd like to publish the pact contract (from consumer) when CircleCI builds from feature and master branch. Now on broker there will be 2 tags (feature and master) for the same contract with same consumer and provider name and contract will be same. When provider test runs and publishes the results i want only contract with "feature" tag to be updated but not the master tag. How can i achieve this?

uglyog
2021-01-26 02:02
You can't. They are the same Pact file, so all tags and results will be applied to it.

uglyog
2021-01-26 02:03
If you want to test that behaviour, make a change so that the Pact file is different on your branch.

natarajang1
2021-01-26 02:05
thanks and appreciate your help!

jmvb.registros
2021-01-26 10:36
Hi all, I started reading about pact not so long ago and I've seen there a few ways to implement the consumer (java8, junit5...) I have a question regarding the assertions of the test. Let's say we have a json object looking like, where we want to check that all the keys (seconds & minutes) are present ```{ seconds: 10 minutes: 20 }``` I've seen a working assertion looking like ```assertFalse(JsonPath.read(httpResponse.getEntity().getContent(), "$.seconds").toString().isEmpty());``` My question is, 1) is there any cleaner way of writing these assertions? 2) how show I implement the consumer to make the assertions more readable and simple?

matt.fellows
2021-01-26 12:10
Pact already makes these assertions as part of what it does. But usually you would be unit testing your API client, and not just issuing HTTP calls to pact in the test code, bypassing your real code. Can you please share your test code so we can help make it clearer?

jmvb.registros
2021-01-26 12:23
```@ExtendWith(PactConsumerTestExt.class) @PactTestFor(providerName = "dateProvider", port = "1234") public class PactAgeConsumerTest { @Pact(consumer = "ageConsumer") public RequestResponsePact validDateFromProvider(PactDslWithProvider builder) { Map<String, String> headers = new HashMap<String, String>(); headers.put("content-type", "application/json"); return builder .given("valid date received from provider") .uponReceiving("valid date from provider") .method("GET") .queryMatchingDate("date", "2001-02-03") .path("/provider/validDate") .willRespondWith() .headers(headers) .status(200) .body(LambdaDsl.newJsonBody((object) -> { object.numberType("year", 2000); object.numberType("month", 8); object.numberType("day", 3); object.numberType("seconds", 3); object.booleanType("isValidDate", true); }).build()) .toPact(); } @Test @PactTestFor(pactMethod = "validDateFromProvider") public void testValidDateFromProvider(MockServer mockServer) throws IOException { HttpResponse httpResponse = Request.Get(mockServer.getUrl() + "/provider/validDate?date=2001-02-03") .execute().returnResponse(); assertThat(httpResponse.getStatusLine().getStatusCode()).isEqualTo(200); assertThat(JsonPath.read(httpResponse.getEntity().getContent(), "$.isValidDate").toString()).isEqualTo("true"); assertFalse(JsonPath.read(httpResponse.getEntity().getContent(), "$.seconds").toString().isEmpty()); } }```

ruben.cagnie
2021-01-26 12:39
Yeah, I should have mentioned that. Thanks for the plug though, it made me look further into annotations!

ruben.cagnie
2021-01-26 13:18
I do run into the issue that both tests write the same contract JSON file, so they are basically overwriting each-other... Any way to specify the name of the JSON file being written?

phil.endsley
2021-01-26 13:19
Somewhere in your code, you should have a method that is making the call to `provider/valiDate.` Instead of making a direct http call to the mock server, you should call that method instead. What you're doing is essentially the same as ```MyClass mockClass = mock(MyClass.class); Mockito.when(mockClass.getNumber()).thenReturn(2); assertThat(mockClass.getNumber()).isEqualTo(2);``` By calling the real method, you couple your test to the actual code that gets invoked in production. This makes sure your actual code and tests don't drift. Another way to think about it, is if you changed your production code to call `/provider/v2/valiDate` , your test above would continue to pass.

bibinc99
2021-01-26 14:37
has joined #pact-jvm

jmvb.registros
2021-01-26 19:43
First of all, thanks for the quick response :clap: I am clearly confused at this point and might be wrong but isn't the point to call a mock provider from the consumer point of view? What I have in mind is 2 separate projects(teams); 1 is the consumer and 1 is the provider. Did you mean to create any sort of DummyConsumer where you just implement these methods? I haven't seen anything like that and but I found in the docs is a similar implementation I'd say https://github.com/pact-foundation/pact-jvm/blob/master/consumer/junit5/src/test/java/au/com/dius/pact/consumer/junit5/ArticlesTest.java I appreciate it and I'm happy to have a look at any docs that you might suggest Thanks

phil.endsley
2021-01-26 19:52
> but isn't the point to call a mock provider from the consumer point of view? Yes > What I have in mind is 2 separate projects(teams); 1 is the consumer and 1 is the provider. Yes, exactly. Of course, the number of each of these can expand to whatever number (1 consumer, 3 providers or whatever combination you need) > Did you mean to create any sort of DummyConsumer where you just implement these methods? No I pressed send too soon, so I'll elaborate more in another comment :slightly_smiling_face:

phil.endsley
2021-01-26 20:00
So, like you said, for a single pact, you'll have one consumer (The application that calls, or consumers, the api) and one provider (The application providing the api). The consumer is responsible for defining the contract. It does this by defining the expectations in unit tests, exactly like you did in your original post. Once the contract is defined, it is generated by running tests that validate the consumer is actually using the api how it says it is. i.e. If a consumer wants to generate a contract that expects a `/provider/valiDate` endpoint, it needs to prove that it actually calls that endpoint. To do this, a unit test is used. When running the unit test, the Pact framework will start a mock server, which serves up the expected contracts as defined by the consumer. The best way to do this, is to call the methods in your code base that make those API requests. When you do this, you're verifying that the consumer is calling all the expected/defined services, and handles the responses in an appropriate way. Once this is done, a contract will be generated. On the provider side, that generated contract is then used to make the defined api calls against the provider. The pact framework then makes sure the responses the provider gives match what is defined in the contract.

phil.endsley
2021-01-26 20:01
When you're writing the consumer tests, this means that your application should be able to configure the host you make calls to, so you can change it to make calls to the mock server for the pact tests.

phil.endsley
2021-01-26 20:04
I need to get around to getting the rest of the branches merged into the official repo, but here's a workshop broken down into different steps of the process: https://github.com/pendsley/pact-workshop-jvm-spring-1/tree/master I know there's also other workshops for other languages. The implementation details might be a little different, but the concepts as a whole apply across all languages

phil.endsley
2021-01-26 20:05
Howtoexamples


phil.endsley
2021-01-26 20:05
Howtolearn

2021-01-26 20:05
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

phil.endsley
2021-01-26 20:05
Those are both good resources for further reading/learning

jmvb.registros
2021-01-26 20:29
Thanks so much for breaking it down. I definitely will check all the mentioned resources and will also check the repo :slightly_smiling_face:

jmvb.registros
2021-01-26 20:30
Much appreciated

jokubas.lekevicius
2021-01-26 20:31
Hi Ruben, The contracts should have different names! Contract names are defined in `.uponReceiving()` (filename depends one the consumer - producer name pairs, which are defined in the class level annotation @PactTestFor(providerName =...) and in the pact @Pact(consumer=..., producer=...) AFAIK)

jmvb.registros
2021-01-26 20:32
I think I see now what you meant when you referred to this `The best way to do this, is to call the methods in your code base that make those API requests. When you do this, you're verifying that the consumer is calling all the expected/defined services, and handles the responses in an appropriate way.`

ruben.cagnie
2021-01-26 20:37
So both my tests test the same consumer+producer. This leads to the json files having the same name and being overwritten...

jokubas.lekevicius
2021-01-26 20:38
That's weird, normally it should write to the same file, but the contracts should be appended to it

ruben.cagnie
2021-01-26 20:39
If you add all the contracts in the same `@Pact` method, then yes it is (which I'm doing now)

matt.fellows
2021-01-26 21:30
Awesome response @phil.endsley :taco:

uglyog
2021-01-26 22:19
It will merge the contents into the Pact file. It will not overwrite it.

abubics
2021-01-26 23:56
I concur, :taco: for @phil.endsley!

luisc.barretog
2021-01-27 00:42
has joined #pact-jvm

laxmi.somni508
2021-01-27 10:27
has joined #pact-jvm

ruben.cagnie
2021-01-27 15:44
Seems like the offender was this `systemProperty("pact.writer.overwrite", "true")`

ryanding16
2021-01-27 20:25
has joined #pact-jvm

ryanlevell
2021-01-27 20:58
Hello. Is it possible to pass consumer version selectors at runtime? I want to verify against only the master-branch-tagged contract during a Pull Request, but then follow-up verifying all the other tags in a non-blocking way. The reason is I don?t want my Pull Requests to be blocked by failed tests if one of my higher environment tagged contracts is failing. But I do want to block my Pull Request if the master-tagged contract is failing. I am also open to other suggestions. Thank you!

uglyog
2021-01-27 21:45
Ah! Yeah, that will do it.

ryanlevell
2021-01-27 21:49
Sorry I am using JVM but realized this might not be JVM specific.

uglyog
2021-01-27 21:55
If you're using JUnit, the annotations default to system properties


ryanlevell
2021-01-27 21:58
Excellent, thank you. For multiple tags is it comma separated?


ryanlevell
2021-01-27 21:59
Thank you

athurner
2021-01-28 13:55
has joined #pact-jvm

alex.mcnair
2021-01-28 18:35
has joined #pact-jvm

kflo
2021-01-28 19:35
question about pact-jvm and scala-pact: it seems to me it would be ideal to have a base java implementation and a separate scala implementation which sits on top of it and provides a more scala friendly DSL, and then have specific framework implementations sit separately on top of that. but it appears right now that pact-jvm and scala-pact have completely separate implementations. i?m just curious about why and if there are any plans to consolidate them at some point

kflo
2021-01-28 19:36
thread here

uglyog
2021-01-28 21:45
Scala-Pact was developed independently of Pact-JVM by the folks at ITV. I guess they thought the could create better support for the Scala eco-system if they built it from scratch.

kflo
2021-01-28 21:46
yep, i?m aware

kflo
2021-01-28 21:47
it seems best, in the long term, to consolidate it into a single implementation stack

kflo
2021-01-28 21:47
i have a fairly good idea now of what scala-pact provides, less so for pact-jvm, i should familiarize myself with it more

uglyog
2021-01-28 21:48
I would have thought they could have use some of the Pact-JVM core modules

kflo
2021-01-28 21:49
me too, i was surprised to see they didn?t

kflo
2021-01-28 21:50
it would be nice to have ?official? support for scala under pact-foundation

uglyog
2021-01-28 21:52
We would need someone with scala knowledge to manage that (handle feature requests, documentation, bug fixes, etc.) There is nobody with that atm.

kflo
2021-01-28 21:57
my company is a scala shop, and we have now adopted pact using the itv/scala-pact implementation at the moment. so i?m happy to help strengthen scala support. i guess i?m wondering where my time is best spent. i could continue working on the itv project, but i think it will always be falling behind the pact-jvm project as it is currently structured

uglyog
2021-01-28 21:59
That's awesome.

uglyog
2021-01-28 22:01
Maybe a way to start would be to start using some of the Pact-JVM libraries. For instance, for accessing a Pact Broker to fetch pacts.

kflo
2021-01-28 22:02
seems reasonable, does it make sense to do that work in the ITV project?

kflo
2021-01-28 22:03
will try to get some of the ITV folks in this thread as well

kflo
2021-01-28 22:03
@david.j.smith for example

kflo
2021-01-28 22:03
don?t want to ?hijack? their project :slightly_smiling_face:

uglyog
2021-01-28 22:05
You can also look at the scala support in Pact-JVM. It is nearly non-existant, and hasn't been looked at by anyone for maybe 5 years.

kflo
2021-01-28 22:05
i did take a quick peak at that, it seems to be a bit behind yes.

uglyog
2021-01-28 22:05
There is also an old ticket to get the SBT plugin working again

uglyog
2021-01-28 22:06
But I would prefer scala-pact to be updated as well

kflo
2021-01-28 22:07
seems like long term it might be better to have the scala stuff in it?s own repository

uglyog
2021-01-28 22:09
I'm ok with that. I had a lot of issues with SBT because of the way it names modules.

kflo
2021-01-28 22:11
eventually the scala libraries should just be a thin layer on top of the java libraries, as well as providing support for SBT

kflo
2021-01-28 22:11
(although you can also use SBT with java? so maybe that should also be in pact-jvm)

kflo
2021-01-28 22:12
anyways, i appreciate the early feedback, hopefully this is just a conversation starter and we can see where it goes

matt.fellows
2021-01-28 23:26
Coming in a bit late here, but generally agree with the sentiment.

matt.fellows
2021-01-28 23:26
I look at it a bit this way, albeit it?s not a completely fair comparison

matt.fellows
2021-01-28 23:27
We have Pact JS (it?s written in TypeScript actually). We get users of both TS and JS and it works as expected. There are many testing libraries too - Jest, Mocha, etc. We have separate packages that extend/adapt Pact JS to work in a more integrated way there

matt.fellows
2021-01-28 23:28
The challenge is maintaining a stable interface, for the ecosystem to innovate around, whilst also adding new features so that the ecosystem doesn?t have to re-invent the wheel

kflo
2021-01-28 23:28
agreed. hoping that stable interface can be pact-jvm

matt.fellows
2021-01-28 23:29
It?s worth exploring, for sure

kflo
2021-01-28 23:29
although maybe there was a good reason itv diverged, i?m not sure of the history

matt.fellows
2021-01-28 23:29
I recall there being a thread on Google Grroups, I can pull it up

kflo
2021-01-28 23:29
thanks!

matt.fellows
2021-01-28 23:30
Often times, it?s curiosity and technically interesting. For some history that I do remember - and ironically - Pact JVM was actually first written in Scala :stuck_out_tongue:

mailinglistsspammedme
2021-01-28 23:30
has joined #pact-jvm


kflo
2021-01-28 23:30
i think it is smart to keep the core in java as it is more portable

matt.fellows
2021-01-28 23:30
over time, that caused issues for non-Scala users (strange exceptions with `$` in them and all of the weirdness you might imagine a language like Java trying to explain Scala issues)

matt.fellows
2021-01-28 23:31
so Scala was stripped away, meaning the interface wasn?t very scala friendly.

kflo
2021-01-28 23:31
oh do i know. i have had to support a groovy application that uses scala JARs


matt.fellows
2021-01-28 23:34
no doubt conversations will be elsewhere in that group

andra.moraru
2021-01-29 07:55
Hi @vuttithatkrongyot yes, we managed to configure everything to run the cucumber tests against the pact mock service.

ranjanayush03
2021-01-29 08:43
Hi I have a query regarding the pacts that gets generated , actually I tried to generate the pacts by using both the jvm and pact-js approach for an end point as there were two seperate consumers consuming the api but on different technologies , the pacts that gets generated using the different approaches are different although on the provider side both the pacts are able to pass the test.

ranjanayush03
2021-01-29 08:45
As in jvm I made use of DslPart to construct the mock response while on js side I used the eachLike property that we need to specify in the body itself

ranjanayush03
2021-01-29 08:46
So the pacts generated are different in the matchers section but both the pacts passes the test , so is there anything that I am doing wrong?

uglyog
2021-01-29 09:00
Pact-JVM supports V3 pact files, while Pact-JS only V2. That's why they are different.

ranjanayush03
2021-01-29 09:02
Okay but the functionality are basically the same for both as in both the pacts were passing the test cases on provider side

ranjanayush03
2021-01-29 09:02
Or are there any difference between the two

matt.fellows
2021-01-29 09:03
Just think of them as equivalent

steven.beaver.retail
2021-01-29 15:34
has joined #pact-jvm

jokubas.lekevicius
2021-01-29 21:50
Hi, is the pact port exposed anywhere as a property, on the consumer side? I would love to use the random port and then inject it into other Spring properties. For now we're using a static port and I would love to avoid that

uglyog
2021-01-30 01:08
Are you using JUnit 4 or 5 tests? There is a mechanism to use a random port.

uglyog
2021-01-30 01:09
For JUnit 4, don't specify a port and then you can get the mock server base URL from the PactProviderRule. For JUnit 5, you just inject MockSever into your test method.

jokubas.lekevicius
2021-01-30 13:01
I'll try to explain my usecase, maybe you'll have an idea how to solve this. I'm using Junit5 and @SpringBootTest to override the providers endpoints, for example, when using Wiremock for more complex tests, I write the annotation like this ```@SpringBootTest(properties = { "external.service.url=http://localhost:${wiremock.server.port}" })``` My goal would be to override the external.service.url with something like ${pact.url} or pact.port.

ekberli.elbrus
2021-01-30 16:33
has joined #pact-jvm

ekberli.elbrus
2021-01-30 16:38
Hi everyone! I'm new in using Pact. Almost 2 days I'm trying to use pact but I cant find Pact Gradle config(plugin, dependency etc.). May anyone send me the simple Gradle config?

jokubas.lekevicius
2021-01-30 18:50
You're trying to configure it on consumer side, yes? Preface, I haven't used gradle for some time. I think the only thing that you need to do, is to import the test dependencies as you probably have junit or mockito imported. If you're using junit5 and java 8, you probably have to import these 2 dependencies: `au.com.dius.pact.consumer:java8:4.1.15` and `au.com.dius.pact.consumer:junit5:4.1.15` . Take my answer with a grain of salt though :smile:

ekberli.elbrus
2021-01-30 20:35
@jokubas.lekevicius thank you))

jokubas.lekevicius
2021-01-30 21:37
Please update if you got it working

natarajang1
2021-01-30 22:17
Hi, how to configure @State to take multiple values on provider side? i tried @State("name1", "name2") but getting --> error: annotation values must be of the form 'name=value'. i referred to example code in this link https://docs.pact.io/implementation_guides/jvm/provider/junit#example-of-http-test. i'm using au.com.dius.pact.provider:junit5spring:4.1.15 jar. Appreciate the help, Thanks.

phil.endsley
2021-01-30 22:20
Not at a computer to verify, but maybe try wrapping the arguments in curly braces

natarajang1
2021-01-30 22:21
yeah, i just tried and it worked... thanks

phil.endsley
2021-01-30 22:27
I guess we should follow up and update that example

uglyog
2021-01-31 00:26
You'll need to raise an issue to get spring support like that. You can try setting the spring property in a before method.

uglyog
2021-01-31 00:27
You can also try inject your class that uses `external.service.url` in the before method and set it there

natarajang1
2021-01-31 03:53
@ekberli.elbrus If you have pact broker and would like to publish the contract you would also need to add ```plugin { id 'au.com.dius.pact' version '4.1.15' } pact { publish { pactDirectory = 'build/pacts' pactBrokerUrl = 'http://<host>:<port>/' // using gitHash as version consumerVersion = getGitHash() } }```

ekberli.elbrus
2021-01-31 06:12
@natarajang1 thank you))

ekberli.elbrus
2021-01-31 06:13
@jokubas.lekevicius I used these and now its working ```plugins { id "au.com.dius.pact" version "4.1.7" } dependencies { testCompile 'au.com.dius.pact.consumer:junit:4.1.7' }```

ekberli.elbrus
2021-01-31 06:16
Hi again! Can anyone explain the difference between pact and postman(I mean on the testing side)? What we can do with Pact which cant do with postman tests?

brendan.donegan
2021-01-31 10:47
Pact provides a framework to enable the consumers of a services endpoints to define the contract with that service in such a way that the service can be confident about making changes without breaking this contract

brendan.donegan
2021-01-31 10:48
With Postman, if you make a change in the service then you can easily just update the test and it will now pass, even though the contract with the consumer is still broken

jokubas.lekevicius
2021-01-31 13:44
Thanks for the suggestions, before trying the workarounds, just wanted to make sure that I'm not missing anything :smile: Thanks for the answer

ekberli.elbrus
2021-01-31 14:34
@brendan.donegan thank you:slightly_smiling_face:


phil.endsley
2021-01-31 14:47
@jokubas.lekevicius :taco:

ekberli.elbrus
2021-01-31 15:15
Hi. I used both configs but I dont know why pact file doesn't create. Do you have any idea? 1st one: ```pact { publish { pactDirectory = 'target/pacts' pactBrokerUrl = 'http://localhost:8000' } }``` 2nd one: ```pact { serviceProviders { provider1 { // All the provider properties are optional, and have sensible defaults (shown below) protocol = 'http' host = 'localhost' port = 8080 path = '/' hasPactWith('consumer1') { pactSource = file('path/to/provider1-consumer1-pact.json') } } } }```

jokubas.lekevicius
2021-01-31 15:23
Are you trying to connect to a pact broker, or just generate a local pact file?

ekberli.elbrus
2021-01-31 16:27
@jokubas.lekevicius yeah just for local

jokubas.lekevicius
2021-01-31 19:47
What happens if you use neither of the configs and run your pact tests. Does the directory `build/pacts` generate for you?


uglyog
2021-01-31 21:52
These configurations are for verifying a provider against a Pact file. Pact files are created by running unit tests on the consumer side.

ekberli.elbrus
2021-02-01 05:48
@jokubas.lekevicius yeah pact file is created on the `build/pacts` but I want to change the directory

ekberli.elbrus
2021-02-01 05:49
@uglyog got it) thank you

jokubas.lekevicius
2021-02-01 07:04
Were you able to change the output directory? If not, I would think that this should work, maybe the problem earlier was that you had both the directory and pactBrokerUrl ```pact { publish { pactDirectory = 'target/pacts' } }```

daniel.tattan.birch
2021-02-01 09:38
has joined #pact-jvm

ekberli.elbrus
2021-02-01 10:38
Solved thank you))

ekberli.elbrus
2021-02-01 10:41
Is there any example for pact provider for localhost? I implemented the consumer and now I want to test it on the provider side.

jokubas.lekevicius
2021-02-01 10:43
Is this how you solved it?

ekberli.elbrus
2021-02-01 10:43
No I just keep my pact file on the build/pacts directory

jokubas.lekevicius
2021-02-01 10:48
https://docs.pact.io/implementation_guides/jvm/provider/gradle Here's a guide on what you need to do with your gradle config And then for the verification test itself, you can use https://docs.pact.io/implementation_guides/jvm/provider/junit5 as for an example project, I'm not sure, maybe others can help

ekberli.elbrus
2021-02-01 10:58
@jokubas.lekevicius I'm getting this error

ekberli.elbrus
2021-02-01 10:59
and my pact file is here

jokubas.lekevicius
2021-02-01 11:03
Can you show the contents of PactProviderTest?

ekberli.elbrus
2021-02-01 11:04
@jokubas.lekevicius

ekberli.elbrus
2021-02-01 11:05
I also tried this one `pact-contract-testing/build/pacts`

jokubas.lekevicius
2021-02-01 11:05
Your pact folder annotation tells Pact to search for pacts in the provider projects scope. What you need to do is to copy the pacts folder to your pact-provider/resources folder

jokubas.lekevicius
2021-02-01 11:06
and you can set your PactFolder to be like `@PactFolder("src/test/resources/pacts")`

ekberli.elbrus
2021-02-01 11:09
@jokubas.lekevicius I did but same situation((

jokubas.lekevicius
2021-02-01 11:11
Make sure the provider names are the same in the consumer and the provider. I'm seeing that the you named your ~consumer~ provider `MyAwesomeService` but the pact file has `test_provider` as the providers name. You might need to edit the name in the consumer and regenerate the pact

matt.fellows
2021-02-01 11:13
also double check the import. I think it should be: ```import au.com.dius.pact.provider.junitsupport.loader.PactFolder;```

matt.fellows
2021-02-01 11:14
I?m sure you?re just testing things out, but the overwhelming use case is to use a Pact Broker

matt.fellows
2021-02-01 11:14
if you?re lazy and just want to go quickly, you can spin up a free http://pactflow.io account for testing and demos.

matt.fellows
2021-02-01 11:15
If you?re going to demo to the team, the broker experience is going to add a lot more weight to the POC

matt.fellows
2021-02-01 11:15
You may also be interested in the Java tutorial (can be done in a browser): https://docs.pactflow.io/docs/tutorials

ekberli.elbrus
2021-02-01 11:21
@matt.fellows Yeah I have to do demo for team. After we'll decide to use pact or postman. What do you think which one we have to use? P.S. i'm working at the bank and we'll implement the BFF(Backend For Frontend)

matt.fellows
2021-02-01 12:03
Pact and postman are really different tools.

matt.fellows
2021-02-01 12:04
With different purposes etx

matt.fellows
2021-02-01 12:04
If you'd like a demo you can book one and we can take you through how pact works and demo to your team if that helps?

ekberli.elbrus
2021-02-01 12:06
@matt.fellows How can I book?

uladzislau_danilchyk
2021-02-01 12:09
Hi there! Maybe @uglyog can look into https://github.com/pact-foundation/pact-jvm/issues/1300 ? :slightly_smiling_face:


jokubas.lekevicius
2021-02-01 16:07
Is there a way to describe an array for a request where the order of the items would not matter? As I understood from the docs, request matching should be as strict as possible, so we need to describe all the expected values in them. With this approach I've encountered a problem. I can't ensure the order of items, because the request model has those in a HashSet, and the order is not guaranteed with it. I wouldn't like to use different kind of Set implementation just to please the testing framework. Let's say I have `.array("list_of_numbers", array -> array.numberValue(1).numberValue(2).numberValue(3))`. It will not always verify that a Set.of(1,2,3) is valid. Maybe I'm doing something wrong here.

jokubas.lekevicius
2021-02-01 20:14
While I'm at it, I'm trying to create test for a possible bug, but I can't get the pact-jvm project to compile on windows, using IntelliJ IDEA and Java 11. Anywhere here's the test code ```@ExtendWith(PactConsumerTestExt.class) @PactTestFor(providerName = "ApiProvider", port = "1234") public class NumberInObjectIssueTest { @BeforeEach public void setUp(MockServer mockServer) { assertNotNull(mockServer); } @Pact(provider = "config-service", consumer = "test-integration") public RequestResponsePact pactForTestWithNumber(PactDslWithProvider builder) { return builder .uponReceiving("Valid number") .path("/url") .method("PUT") .headers(Collections.singletonMap("Content-Type", ContentType.JSON.toString())) .body(LambdaDsl.newJsonBody(body -> body.numberValue("valid_number", 1.0)).build()) .willRespondWith() .status(200) .body("{\"data\":\"\", \"status\":\"success\"}") .toPact(); } @Test @PactTestFor(pactMethod = "pactForTestWithNumber") public void runTest(MockServer mockServer) { RequestLoggingFilter requestLoggingFilter = new RequestLoggingFilter(); ResponseLoggingFilter responseLoggingFilter = new ResponseLoggingFilter(); RequestSpecification requestSpec = new RequestSpecBuilder() .setContentType(ContentType.JSON) .setPort(mockServer.getPort()) .setBasePath("/url") .addFilter(requestLoggingFilter) .addFilter(responseLoggingFilter) .setBody(new RequestModel(1.0)) .build(); Response response = given().spec(requestSpec).put(); assertEquals("success", response.body().jsonPath().get("status")); } private static class RequestModel { private final Double validNumber; private RequestModel(Double validNumber) { this.validNumber = validNumber; } public Double getValidNumber() { return validNumber; } } }``` The problem is that I thought that a number is also an integer, but pact is telling me it's not.

george.south
2021-02-01 21:12
has joined #pact-jvm

abubics
2021-02-02 00:58
By default, I think there are no unordered set matchers. You could add a custom matcher, I guess? There is a general concern, though, about returning non-deterministic responses (which interferes with caching, and probably other things).

uglyog
2021-02-02 01:12
Ignoring array order has been added to 4.2.0.


abubics
2021-02-02 01:20
v4, so aspirational :heart:

ekberli.elbrus
2021-02-02 06:50
Hi everyone! Is it possible to write provider and consumer test in one package. Like below:

jokubas.lekevicius
2021-02-02 07:11
I think there's no stopping you from using both in one package, but that doesn't really make sense even in a demo scenario

matt.fellows
2021-02-02 07:44
Can you please elaborate on why? No technical reason you couldn't tho but it's certainly not the normal practice

ekberli.elbrus
2021-02-02 09:00
@matt.fellows Because I think in both case on provider side we just forward provider to the real provider link. That's why I think there is no need to additional module on the project

matt.fellows
2021-02-02 10:43
when you say ?forward to the provider?, do you mean that you point the verification at the running provider environment (e.g. staging/test)? That is also not best practice

ekberli.elbrus
2021-02-02 10:57
@matt.fellows Yeah as you see on below. First I run the UserApp and I point the UserApp on the provider

ekberli.elbrus
2021-02-02 10:58
What is the best practice for that? What should I do?

matt.fellows
2021-02-02 10:58
I?m sorry, screenshots of your IDE aren?t really helping with this conversation!

matt.fellows
2021-02-02 10:59
Your provider tests aren?t owned by the consumer - whoever owns the provider code base should be responsible for doinsg this. Related to this, the tests should run _with the provider tests_ not with the consumer test

matt.fellows
2021-02-02 10:59
there are a myriad of workflow issues that aren?t worth discussing right now, but if you don?t do it the way described above, you?ll be severely limited in your outcomes



ekberli.elbrus
2021-02-02 11:01
Okay. thank you very much @matt.fellows :slightly_smiling_face:

matt.fellows
2021-02-02 11:02
this is the full guide for CI/CD (which links to a really good workshop): https://docs.pact.io/pact_nirvana

matt.fellows
2021-02-02 11:02
If I recall, you were possibly wanting a demo with the team? If so, I (or somebody else in the team) can take you through a version of all of this in that session

mhdtouban
2021-02-03 00:15
Hi, am trying to publish the pact using `./gradlew pactPublish` but getting this error ```java.io.FileNotFoundException: /StudioProjects/andromeda/build/pacts``` i don't see pact generated in build folder but it's available in /target/pacts

uglyog
2021-02-03 00:23
If the pact files are in `targets/pacts` then you need to specify that directory

mhdtouban
2021-02-03 00:36
i added this to the the build.gradle ```apply plugin: 'java' // adds 'test' task test { systemProperties['pact.rootDir'] = "$rootDir/Andromeda/target/pacts" }``` but doesn't seems to be changing the directory

uglyog
2021-02-03 00:41
That changes the directory the pacts are written to when the tests run, not the directory the pacts are published from

twierzchowski
2021-02-03 07:05
has joined #pact-jvm

yassin.hajaj
2021-02-03 10:35
has joined #pact-jvm

yassin.hajaj
2021-02-03 10:36
:man-raising-hand:

kjayachandra2000
2021-02-03 11:35
```pact { publish { pactDirectory = '/target/pacts' pactBrokerUrl = 'url' pactBrokerUsername = 'username' pactBrokerPassword = 'password' } }``` just adding this incase it can be of any help :slightly_smiling_face: . document https://docs.pact.io/implementation_guides/jvm/provider/gradle#publishing-pact-files-to-a-pact-broker

dany.marques90
2021-02-03 12:48
has joined #pact-jvm

marcelo
2021-02-03 13:11
has joined #pact-jvm

sandeeparthur
2021-02-03 19:46
has joined #pact-jvm

uladzislau_danilchyk
2021-02-04 09:17
@uglyog, did you have a chance to have a look at this?

octoberclub
2021-02-04 16:27
has joined #pact-jvm

slavick
2021-02-04 17:21
has joined #pact-jvm

imran.settuba
2021-02-04 18:57
has joined #pact-jvm

christopher.roberts
2021-02-05 01:02
has joined #pact-jvm

christopher.roberts
2021-02-05 01:05
I just tried initializing my consumer / provider pacticipant names from an environment variable and it didn't work. Is this supported?

matt.fellows
2021-02-05 01:11
I just did some googling (read: fumbling). I?m assuming there needs to be some parameter resolver that is aware of this.

matt.fellows
2021-02-05 01:12
I can see the provider side has these imports: ```import au.com.dius.pact.core.support.expressions.SystemPropertyResolver; import au.com.dius.pact.core.support.expressions.ValueResolver;```

matt.fellows
2021-02-05 01:12
The provider (Junit5) has: ```import org.junit.jupiter.api.extension.ParameterResolver```

christopher.roberts
2021-02-05 01:16
I'm writing my consumer contract test at the moment, and I tried the following: `@PactTestFor(providerName = "${CI_PROJECT_NAME}", port = "1234")`

uglyog
2021-02-05 01:17
If they're set with annotations, they can not be overridden

matt.fellows
2021-02-05 01:18
Yeah, looking at the annotation definitions for things like `PactTestFor` and `Provider` there is no parameter resolver, unlike the `PactBroker` annotation

matt.fellows
2021-02-05 01:20
Is there a system property that can be used instead of the annotation? Searching through the docs I can?t see

christopher.roberts
2021-02-05 01:24
Another thing I tried which didn't work was: `System.setProperty("pact.provider.name", System.getenv("CI_PROJECT_NAME"));`

christopher.roberts
2021-02-05 01:24
In this case I'm trying to write a generic test which will test a common endpoint of all services in an inheritable project (for context)

matt.fellows
2021-02-05 01:30
yep I also tried this. Then I looked at the source and realised it wouldn?t work that way

matt.fellows
2021-02-05 01:30
or at least, I think it makes sense looking at it

r.darcel
2021-02-05 09:15
has joined #pact-jvm

christopher.roberts
2021-02-05 23:46
I was able to hack it to work by overriding `PactTestFor` and `PactConsumerTestExt` btw. On the provider side, I could actually use `pact.provider.name` . Still, it would be nice if it worked out of the box :)

uglyog
2021-02-06 00:50
If you could create a PR with your changes, that would be awesome.

ashish.joshi
2021-02-06 01:07
has joined #pact-jvm

christopher.roberts
2021-02-06 02:17
Is all the code in https://github.com/pact-foundation/pact-jvm ? I couldn't find the .kt file for `PactTestFor` in there


christopher.roberts
2021-02-06 02:27
ah ok, was looking at version 4.1.8

christopher.roberts
2021-02-06 02:50
remote: Permission to pact-foundation/pact-jvm.git denied to *****

uglyog
2021-02-06 02:55
Just clone it to your account, make the changes and then create the PR


przemek.sech296
2021-02-08 23:18
has joined #pact-jvm

vplows
2021-02-09 06:00
has joined #pact-jvm

wesleythomaswilliams
2021-02-09 13:02
.

rodney.stromlund
2021-02-09 16:18
has joined #pact-jvm

nada
2021-02-09 19:00
has joined #pact-jvm

siddhardhan
2021-02-09 20:21
has joined #pact-jvm

josh.rosenfeld
2021-02-09 20:30
Encountered an issue that I was hoping to get some clarity on. We have set up a provider for our monolithic service that builds through Bazel. Today, we added a second provider test class that tests a different endpoint in our service. When we run both classes, it errors with: `MissingStateChangeMethod: Did not find a test class method annotated with @State("Our first endpoint test") for Interaction ("our first endpoint") and Consumer SomeService`. Basically, our second provider test class fails because it is unable to verify the interaction that is verified in the first provider test class. Is it by design that all provider tests for a service should be consolidated to a single class or is this rather an issue possibly with Bazel not carrying Pact context over to the next test class it runs?

pbobba
2021-02-09 22:58
Hello pact-enthusiasts, I?m having trouble with fuzzy matching in pact-jvm. I?m trying to write a junit5 test which looks kinda like the attached _*dummyPact.java*_ file. When using pact-verify, I don?t really care for the value of field *?nums?* but I care about whether it?s an integer or not. The above test is generating _*generated.json*_ whereas the other _*tampered.json*_ is the one edited (matchingRules section) by hand to pass pact verification. You can refer to https://www.diffchecker.com/X9MZgA1c link to see the difference between generated vs tampered json files. I?ve referred to examples https://github.com/pact-foundation/pact-jvm/blob/00f3fe69955aa8e1eb988b7afbdfc1e5807cb851/consumer/junit/src/test/java/au/com/dius/pact/consumer/junit/Defect266Test.java and https://github.com/pact-foundation/pact-jvm/blob/00f3fe69955aa8e1eb988b7afbdfc1e5807cb851/consumer/junit/src/test/java/au/com/dius/pact/consumer/junit/WildcardKeysTest.java before posting here. Any help is appreciated! Thank you. @lbraymusso for visibility

uglyog
2021-02-10 00:55
You can share the state annotations between the tests by using interfaces or a base class. See https://github.com/pact-foundation/pact-jvm/blob/master/provider/junit/src/test/java/au/com/dius/pact/provider/junit/StateAnnotationsOnInterfaceTest.java for an example

josh.rosenfeld
2021-02-10 01:00
ah, interesting. So is it by design that you are either using one provider test class or several connected through interfaces or inheritance?

uglyog
2021-02-10 01:02
`eachKeyLike` is for matching all the attributes in an object. Do you expect to have more than one attribute like `nums`?

uglyog
2021-02-10 01:04
Yes, normally there would be one test. But there are mechanisms to filter based on consumer names or provider states.

lbraymusso
2021-02-10 01:47
Shouldn't be for this use case - an example response object for this scenario might look like the following: ```{ "nums": 0, "aggregations": {}, "rates: {}, }``` I believe `eachKeyLike` was something we simply tried after exhausting the original approaches with `numberType` (eg. `.numberType("nums", 782782)`) and `integerType` which we were unable to get working.

lbraymusso
2021-02-10 01:47
Essentially, we only care to match the data _types_ for each of the response body's keys (`nums` should be int, `aggregations` and `rates` should be obj) but in practice, the verification always fails on `nums` because it's expecting a literal value to be matched. The only way we've gotten around it is to manually add the `matchingRules` for `$.nums` to the contract (as shown in `tampered.json`) :sweat_smile:

uglyog
2021-02-10 02:11
That is exactly what `integerType` will do, what version of Pact-JVM are you using?

lbraymusso
2021-02-10 02:15
checking...

lbraymusso
2021-02-10 02:21
looks like the project's pact dependencies are ``` testImplementation 'au.com.dius.pact.consumer:junit5:4.1.0' testImplementation 'au.com.dius:pact-jvm-model:3.5.1'```

lbraymusso
2021-02-10 02:22
also of note: we're using a docker image (`pactfoundation/pact-cli:0.6.0.2`) to verify the resulting contract artifact against the provider endpoint, in case that's relevant here. of course, running the initial consumer contract test via junit works just fine, but the crux of the issue is that the generated contract (ie. `generated.json`) never furnishes the appropriate matching rules (as seen in `tampered.json`) we need to get past verification later on.

uglyog
2021-02-10 02:24
Don't mix the major versions of the Pact-JVM libs: 4.1.0 and 3.5.1. That is what is probably what is causing the issues.

lbraymusso
2021-02-10 02:28
ah, I thought that looked odd when i checked. caveat here is that I wasn't directly involved in setting up the project, so there might be a backstory to how we landed on those dependencies which i'm not privy to. hopefully Prathyusha can chime in later on, in case there was a reason for that deviation :smile: in the interim, is there a recommended combination that would be preferable (4.x versus 3.x) - and would that simply be a matter of bringing the dependencies in lockstep? eg: ``` testImplementation 'au.com.dius.pact.consumer:junit5:4.1.0' testImplementation 'au.com.dius:pact-jvm-model:4.1.0'```

uglyog
2021-02-10 02:35
``` testImplementation 'au.com.dius.pact.consumer:junit5:4.1.16' testImplementation 'au.com.dius.pact.core:model:4.1.16'```

uglyog
2021-02-10 02:35
Might as well use the latest version

lbraymusso
2021-02-10 02:36
indeed! will give it a go

lbraymusso
2021-02-10 02:43
looks like it's close - consumer test actually seems to be failing on something silly now, like it's enforcing a strict sequence for the response body keys: ```Expected :{\"nums\":0,\"aggregations\":{\"rates\":{}}} Actual :{\"aggregations\":{\"rates\":{}},\"nums\":0}``` i vaguely recall reading about some option to ignore the order - not sure if that would apply here?

lbraymusso
2021-02-10 02:49
this is how the relevant bit of code looks at the moment: ``` private static final String responseForFalseSku = new PactDslJsonBody() .integerType("nums", 0) .object("aggregations") .object("rates") .closeObject() .closeObject().toString();```

uglyog
2021-02-10 02:51
Don't call `toString()`, because you will loose all the matching rules. Pass the result directly to the `body` method

lbraymusso
2021-02-10 03:00
Ahh, good call

lbraymusso
2021-02-10 05:06
all right, just had a chance to tweak this so it's no longer sending the pact Dsl to a string: ``` private static final DslPart responseForFalseSku = new PactDslJsonBody() .integerType("nums", 0) .object("aggregations") .object("rates") .closeObject() .closeObject();``` it's still failing for the same sequencing reason as pasted above (albeit, slightly different now that it's a JsonObject rather than String being compared): ```Expected: is <{"numFound":0,"bucketAggregations":{"PrvRating":{}}}> but: was "{\"bucketAggregations\":{\"PrvRating\":{}},\"numFound\":0}"``` here's the relevant test method, which i modified to pass in the `DslPart` rather than `String` for `requestFalseSku` and `responseForFalseSku` : ``` @Pact (consumer="sf-reviews-provider") public RequestResponsePact skusNotFound(PactDslWithProvider builder) { return builder .given("A sku which is not found") .uponReceiving("test interaction") .path("/reviews/skus") .method("POST") .headers(headers) .body(requestFalseSku) .willRespondWith() .status(HttpStatus.OK.value()) .body(responseForFalseSku) .toPact(); } @Test @PactTestFor(pactMethod = "skusNotFound") void testSkusNotFound(MockServer mockServer) throws IOException { HttpResponse httpResponse = post(mockServer, requestFalseSku.toString()); assertThat(httpResponse.getStatusLine().getStatusCode(), is(equalTo(HttpStatus.OK.value()))); assertThat(CharStreams.toString(new InputStreamReader(httpResponse.getEntity().getContent(), Charsets.UTF_8)), is(equalTo(responseForFalseSku))); }```

lbraymusso
2021-02-10 05:07
(_that said:_ when i comment out that final problematic `assertThat` line and just let it run, the generated contract is looking much better :smile: `matchingRules` and all :thumbsup: )

uglyog
2021-02-10 05:07
Yeah, I was about to say that is not relating to the Pact libraries, but the assert

lbraymusso
2021-02-10 05:15
right. i'm just stuck on why it's trying to enforce the order of the keys so strictly - is that the expected behavior? on a whim, i tried adjusting `responseForFalseSku` to match the _literal_ order of the response body, but got an IDE error (`Cannot resolve method 'integerType' in 'DslPact'`) so i'm assuming there's restrictions on the order in which `PactDslJsonBody` can be built: ``` private static final DslPart responseForFalseSku = new PactDslJsonBody() .object("aggregations") .object("rates") .closeObject() .closeObject() .integerType("nums", 0); // throws 'Cannot resolve method' error``` either way, having to reorder the lines like that feels icky, even if that _did_ work, so the better question is probably - is there an advisable way we should rework that final assert statement so it's less strict about matching the order of the keys?

uglyog
2021-02-10 05:17
The issue is you are asserting that the response as a string is exactly equal to the generated JSON as a string. Try instead to parse the response to a JSON or a model object and assert on that.

lbraymusso
2021-02-10 05:21
cool, that's the approach i was leaning towards - just wanted to make sure i wasn't missing something obvious before proceeding. thanks! i'll give that a shot tomorrow and let you know how it goes - thanks for all your help so far, massively useful :raised_hands:

lars.hisken916
2021-02-10 08:08
has joined #pact-jvm

pauligoe10
2021-02-10 08:19
has joined #pact-jvm

tusharvarm
2021-02-10 09:38
has joined #pact-jvm

tusharvarm
2021-02-10 09:40
Hello..I have a json file which contains 25-30 fields in it and it is very difficult for me to create a pact body using LambdaDslJsonBody class. is there any way that I can parse the json file to LambdaDslBody object and use it to create pact file?

laxmi.somni508
2021-02-10 10:33
Hello Helpful folks, What is a best plugin/library for using PACT-Java in a project written in Scala code-base? If you've any sample example on Git/Stackoverflow of this kind then kindly let me know. Thanks STAY HOME-STAY SAFE:pray:

igorsharf
2021-02-10 10:39
has joined #pact-jvm

matt.fellows
2021-02-10 11:55
Might also be worth asknig in #pact-scala-itv

matt.fellows
2021-02-10 11:55
I?m not sure there _is_ a plugin/lib to do that. You either use Pact JVM or the scala variant. Keen for other perspectives

matt.fellows
2021-02-10 11:55
e.g. @kflo

laxmi.somni508
2021-02-10 11:56
We've the project code-base in Scala, but would like to try Pact JVM (Java variant) on top of it for Pact testing (Provider-side)

matt.fellows
2021-02-10 12:00
So are you looking for something else (you mentioned a plugin)

pbobba
2021-02-10 14:57
Went through the discussion. I din't think about checking for version clash. That's a nice catch. We set up this project 3.5 months ago so I don't recall the reason why those exact versions were chosen. Thank you both for spending time on this.

pbobba
2021-02-10 16:28
I've changed the versions as suggested ``` testImplementation 'au.com.dius.pact.consumer:junit5:4.1.16' testImplementation 'au.com.dius.pact.core:model:4.1.16'``` and am using ```pactfoundation/pact-cli:0.31.0.0` for verification.``` Matching rules are looking much better now but with `numberType` or `integerType` match shows up as ```"matchers": [ { "match": "integer" } ],``` This is still causing a failure in verification when expected value is not the same.

josh.rosenfeld
2021-02-10 17:12
i see. Thanks for clearing that up! That's very helpful

kieran
2021-02-10 17:13
has joined #pact-jvm

kflo
2021-02-10 17:33
@laxmi.somni508 unfortunately the pact-jvm library doesn?t have great scala support right now, both for SBT or for scala test frameworks (like scalatest). it is easiest to integrate with scala-pact https://github.com/ITV/scala-pact

kflo
2021-02-10 17:35
also of note, scala-pact does not implement pact-jvm, they are two divergent implementations at the moment

poward
2021-02-10 18:17
has joined #pact-jvm

ckhadilkar
2021-02-10 21:16
has joined #pact-jvm

matt.fellows
2021-02-11 01:56
is there any reason, apart from the fact that the DSL itself is not scala native, that Pact JVM couldn?t be used from within a Scala project?

lbraymusso
2021-02-11 02:20
I was able to reproduce the behavior Prathyusha describes FWIW -- here is an expanded snippet of the relevant portion of the newly-generated contract: ``` "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=UTF-8" }, "body": { "numFound": 10, "bucketAggregations": { "PrvRating": { } } }, "matchingRules": { "body": { "$.numFound": { "matchers": [ { "match": "integer" } ], "combine": "AND" } }, "header": { "Content-Type": { "matchers": [ { "match": "regex", "regex": "application/json(;\\s?charset=[\\w\\-]+)?" } ], "combine": "AND" } } } },```

uglyog
2021-02-11 02:23
@pbobba `pactfoundation/pact-cli` does not support any of the V3 features (like the number type matcher). You need to use a normal type matcher.

lbraymusso
2021-02-11 02:24
Ah, I didn't realize that feature was part of the V3 spec. Are there any future plans to support V3 in the CLI image?

lbraymusso
2021-02-11 02:28
Alternatively - what did you mean by normal type matcher? is there a way we could still run verification through docker?

uglyog
2021-02-11 02:31
Hmm, that's a good point, there is no general `like` method on PactDslJsonBody. I'll add one.

uglyog
2021-02-11 02:32
I don't have any plans to upgrade pactfoundation/pact-cli to V3, and I haven't heard of anyone else mentioning that. But it needs to be done at some point.

lbraymusso
2021-02-11 02:33
Ah yeah, i think that's what was throwing me - we were able to achieve fuzzy matching with the `pact-python` client (which i'm fairly sure uses V2 spec for the most part) with the regular `Like` keyword, which i couldn't find an equivalent for in `pact-jvm` & thought i was missing something obvious :sweat_smile: that would be great!

lbraymusso
2021-02-11 02:33
Looks like there's an open issue about V3 support in the CLI repo already - https://github.com/pact-foundation/pact-provider-verifier/issues/61

lbraymusso
2021-02-11 02:35
FWIW, the use case for us preferring the `pact-cli` image is primarily the language agnosticism + ability for us to more easily support Pact in CI via Docker - we have to support engineers across ~4-5 major languages, so it's difficult to standardize on pact implementation without a common wrapper like that

uglyog
2021-02-11 02:35
The `pactfoundation/pact-ref-verifier` supports V3 spec, you could try use that instead

lbraymusso
2021-02-11 02:36
oh neat, i'll check that out. as a quick sanity check, does this also mean that things like Message Pact will not work with `pact-cli` ?

uglyog
2021-02-11 02:37
I don't know about Message Pact support with `pact-cli`, @matt.fellows might be able to answer that

lbraymusso
2021-02-11 02:38
ah wait, I just realized the 'V3 not supported' PR I linked to is _from_ the `pact-provider-verifier` repo :facepalm:

lbraymusso
2021-02-11 02:39
I'll give it a shot either way though since now i'm curious, hadn't seen the verifier before now

lbraymusso
2021-02-11 02:42
one final Q that came up in the course of debugging the fuzzy matching stuff above - after making the recommended changes, I noticed that the newly-generated contract was adding `charset=UTF-8` to the expected response and matchingRules, even though we've not defined this anywhere in our code (just `application/json`): ``` Failure/Error: expect(header_value).to match_header(name, expected_header_value) Expected header "Content-Type" to equal "application/json; charset=UTF-8", but was "application/json"``` Any idea how / why this would be happening in the contract? ``` "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=UTF-8" },``` ``` "header": { "Content-Type": { "matchers": [ { "match": "regex", "regex": "application/json(;\\s?charset=[\\w\\-]+)?" }```

uglyog
2021-02-11 02:54
It adds that if the content type header is not set. If you set the header first, it will not add that.

lbraymusso
2021-02-11 02:56
hmm. do you mean setting it somewhere other than here? ``` @Pact (consumer="sf-reviews-provider") public RequestResponsePact skusNotFound(PactDslWithProvider builder) { return builder .given("A sku which is not found") .uponReceiving("test interaction") .path("/reviews/skus") .method("POST") .headers(headers) .body(requestFalseSku) .willRespondWith() .status(HttpStatus.OK.value()) .body(responseForFalseSku) .toPact();``` where `headers` is defined as `private Map<String, String> headers = Map.of("Content-Type", "application/json");`

matt.fellows
2021-02-11 02:58
you haven?t set a _response_ header, just a request one

lbraymusso
2021-02-11 02:58
oooof, right you are!

lbraymusso
2021-02-11 02:59
good catch

lbraymusso
2021-02-11 02:59
while you're here, @matt.fellows - not sure if you happened to catch the question above about whether `Message Pact` would be supported by `pactfoundation/pact-cli` ?

matt.fellows
2021-02-11 03:03
It kind of does, but not in a way that?s straightforward

matt.fellows
2021-02-11 03:03
I think the new rust based one would be a better path forward (e.g. https://github.com/pact-foundation/pact-reference/releases/tag/pact_verifier_cli-v0.8.4)

matt.fellows
2021-02-11 03:03
I haven?t tried message pact that way though. At a minimum, you?d need to start an HTTP server so that the CLI could ?invoke? your message providers

matt.fellows
2021-02-11 03:03
this for provider verification or consumer?


lbraymusso
2021-02-11 03:04
this would be for both, eventually - we're evaluating a way to broadly implement support for message pacts in a way that could be leveraged in CI

lbraymusso
2021-02-11 03:06
(we've intentionally restricted use cases to HTTP services for now since Message Pact support isn't evenly applied across all the client languages we'd need to potentially accommodate)

matt.fellows
2021-02-11 03:06
What were the languages you needed again? I think Java, Python were already discussed - what else?

lbraymusso
2021-02-11 03:08
Python was the biggest one because a ton of our python microservices are starting to use Kafka - at last check, Consumer support was _just_ added to pact-python https://github.com/pact-foundation/pact-python/pull/194, and the Provider support is https://github.com/pact-foundation/pact-python/pull/200, so we're chomping at the bit to evaluate that once it's merged in :smile:

lbraymusso
2021-02-11 03:09
other languages we'll eventually need to support are PHP, Javascript, and .NET -- I _think_ Message Pact is supported with PHP and JS, not sure about dotnet though

matt.fellows
2021-02-11 03:09
Yep, we had a few folks over here do the initial implementation. You can see how they did it if you were interested in porting that to .NET.

matt.fellows
2021-02-11 03:09
It?s not a huge amount of work to be honest, but we don?t have the .NET skills here to do it

matt.fellows
2021-02-11 03:10
There is no CLI tool for the consumer side I?m afraid

lbraymusso
2021-02-11 03:10
Gotcha. so meaning that there'd be no way to use the CLI to verify/publish consumer contracts that use Message Pact? or am i misunderstanding

matt.fellows
2021-02-11 03:11
that?s right. The way consumers work just doesn?t lend itself to a CLI tool this way. The provider side is a bit easier

matt.fellows
2021-02-11 03:12
Python (beta), Java, PHP, JS and Golang all have message support. It?s just .NET you?re losing out on

matt.fellows
2021-02-11 03:12
so you?re probably better off investing any effort to ?standardise? into the .NET DSL, rather than trying to build a generic consumer side message pact CLI

lbraymusso
2021-02-11 03:13
That's probably fine for now TBH (the language support for messages) - the biggest users of Kafka are Python & Java devs , we dont have many .NET users

matt.fellows
2021-02-11 03:13
or at least, I?m all ears on how you?d do it - because it would be handy to have a CLI approach

lbraymusso
2021-02-11 03:13
As for the CLI support for consumers, it's probably just because i haven't gotten my hands dirty with the consumer side of message pact that i didn't know there were added complexities there

lbraymusso
2021-02-11 03:14
But the ability for us to provide a generic consumer-side verification/publish capability for multiple languages (in CI) has been a huge plus for adoption just on HTTP services alone, so it's definitely something i'd want to look into once i have a chance to evaluate the Pact Python message support

matt.fellows
2021-02-11 03:15
Can you please elaborate on that? What have you done to standardise it?

matt.fellows
2021-02-11 03:15
that sounds interesting

lbraymusso
2021-02-11 03:15
Not sure how familiar you folks are with Buildkite (Melbourne based as well I believe?) but we've been building out a BK plugin for Pact - hence the need for it to be as 'one size fits all' as possible - within reason :stuck_out_tongue:

lbraymusso
2021-02-11 03:15
Planning to open source it eventually if others would find it useful

matt.fellows
2021-02-11 03:20
very familiar with BK! :stuck_out_tongue:

matt.fellows
2021-02-11 03:20
(we use it here as well FWIW)

matt.fellows
2021-02-11 03:20
and yes, would love to see that

lbraymusso
2021-02-11 03:20
oh, awesome! that would explain this - https://github.com/pact-foundation/pact-specification/issues/42 :stuck_out_tongue: (which can be closed, btw, there's a pact emoji on BK now!)

matt.fellows
2021-02-11 03:20
what does the BK plugin actually _do_ though

matt.fellows
2021-02-11 03:21
is there! Cool!

lbraymusso
2021-02-11 03:21
Yeah, i was planning to add one but someone beat me to it back in May lol


matt.fellows
2021-02-11 03:22
nice

lbraymusso
2021-02-11 03:25
So, at the moment, the plugin basically just wraps the `pactfoundation/pact-cli` and exposes the CLI args as plugin parameters so that any of our devs can use it regardless of language (and regardless of whether they are a consumer or provider service, since the CLI supports both) - so there's basically two main flows, the 'consumer' flow which validates the contract and then publishes it to the broker, and the 'provider' flow which pulls the contract down from the broker and runs verifications before deploy. it also supports the ability to spin up a dockerized instance of the service under test (part of the reason we prefer using docker for the CI solution - so pact and the provider service can be orchestrated together using docker compose)

matt.fellows
2021-02-11 03:26
how are the tests actually run though - in the context of the standard unit test framework? or only via the CLI itself?

matt.fellows
2021-02-11 03:27
I?m assuming on the consumer side, it?s just doing the `pact-broker publish` command and `pact-broker can-i-deploy` command right?

lbraymusso
2021-02-11 03:27
Yep, the tests still have to be run in a required preceding step - the plugin only handles everything from the "contract has been generated" state on

matt.fellows
2021-02-11 03:27
got it

lbraymusso
2021-02-11 03:27
that's where we drew the line on language agnostic support :smile:

matt.fellows
2021-02-11 03:27
got it

matt.fellows
2021-02-11 03:27
what you?re doing is exactly what we would recommend people do.

matt.fellows
2021-02-11 03:27
that?s why we docker it

lbraymusso
2021-02-11 03:27
glad to hear it!

matt.fellows
2021-02-11 03:27
on the provider side, I?m gathering you run the `pact-provider-verifier` command then and _not_ the provider side contract test in the native language?

lbraymusso
2021-02-11 03:32
i think it's just the generic `verify` command provided by `pact-cli` but yeah, def not using the native language for provider-side verification

matt.fellows
2021-02-11 03:32
oh yeah, that dispatches to the same command basically

lbraymusso
2021-02-11 03:33
yup

lbraymusso
2021-02-11 03:34
it's funny, we were literally just talking about plans to open source the plugin today - would love to connect with you guys once we have a beta version released to see if we're on the right path!

tusharvarm
2021-02-11 04:43
Can anyone please suggest me solution on this?

laxmi.somni508
2021-02-11 10:34
@matt.fellows - Thanks for your response. Yes. I meant a bridging plugin / library / example of implementation of Pact-JVM using Java, in a project having Scala /Play framework based code base

neild
2021-02-11 18:53
has joined #pact-jvm

kflo
2021-02-11 21:00
@matt.fellows you could certainly use pact-jvm within a scala project, but you?d have to write some integration code yourself in order to use it effectively with build tools like SBT and test frameworks. it?s do-able though. i started a thread awhile back about trying to reconcile the two projects so that the scala version of pact is built on top of the java version so they can better stay in sync? when i have a little more free time i?d like to explore what that would look like. hoping it wouldn?t be too big of a lift

mhdtouban
2021-02-11 22:14
hey, just a quick question cause I didn't find this in documentation. is there a way to pass a parameter through Gradle to publish task ? something like `./gradlew pactPublish -PpactBrokerToken=""`

painenigowthami
2021-02-11 22:32
has joined #pact-jvm

stephenkilbourn
2021-02-11 23:02
has joined #pact-jvm

tcarlson
2021-02-11 23:05
has joined #pact-jvm

uglyog
2021-02-12 00:04
If you configure it like so: ```pact { broker { pactBrokerUrl = 'https://your-broker-url/' pactBrokerToken = project.pactBrokerToken } }``` then the parameter will set the project property

mhdtouban
2021-02-12 01:02
hmm this token would be stored in a secured place (env. variables) in our CI and then passed by when calling the publish job.. so storing it in the project wouldn't be a feasible option

uglyog
2021-02-12 01:13
It's not stored in the project. All Gradle properties (including any created using `-P` ) are accessible on the Gradle `project` object

mhdtouban
2021-02-12 01:17
hmm trying out `./gradlew pactPublish -PpactBrokerToken="my token"` doesn't seem to be passing the token. also i had to add pactBrokerToken inside my `gradle.properties` file otherwise it will complain about ```Could not get unknown property 'pactBrokerToken' for root project of type org.gradle.api.Project.```

uglyog
2021-02-12 01:18
Ah, but the value comes from the command line?

mhdtouban
2021-02-12 01:21
yes i can see the value when printing it but the publish failed for some reason

mhdtouban
2021-02-12 01:21
401

uglyog
2021-02-12 01:21
That means the token was not correct

mhdtouban
2021-02-12 01:24
yeah i guess token was revoked because multiple failed tries. it's working out now with new token. Thanks

tusharvarm
2021-02-12 05:06
Hello Folks..I have a json file which contains 25-30 fields in it and it is very difficult for me to create a pact body using LambdaDslJsonBody class. is there any way that I can parse the json file to LambdaDslBody object and use it to create pact file?

abubics
2021-02-12 05:11
There are a couple of concerns to go with this . . . ? Are all of those fields significant for every interaction? ? JSON on its own doesn't represent the flexible matchers without building a new DSL, so the answer will probably stay "no"

abubics
2021-02-12 05:11
(When you say "I have a json file", I assume you mean that's the response from an API saved as a file . . . correct that if I'm wrong, please)

abubics
2021-02-12 05:13
If you want some kind of reuse, I'm sure there are ways to build that with helper functions, but that may be missing the point of writing unit tests that describe the interactions.

matt.fellows
2021-02-12 05:34
I do think there is merit in being able to do something like this `like({?representative json blob})` sort of thing, like what you can do in Pact JS for example

matt.fellows
2021-02-12 05:34
that would make it a simple way to get started

matt.fellows
2021-02-12 05:35
but as soon as you need to have specific matching rules on any property or nested value, you?re going to create a wrapper that?s eventually going to be as powerful as the one you?re trying to abstract away from :wink:

abubics
2021-02-12 05:51
yarr . . . it doesn't chop much off the start of the learning curve, but maybe still helpful

tusharvarm
2021-02-12 06:57
@abubics All the fields in the json file are required files. Also it is the request of the API endpoint which is created in form of json file

tusharvarm
2021-02-12 06:58
@abubics Do we have some kind of third party library which can be used to parse Json file to LambdaDslJsonBody object?

abubics
2021-02-12 06:59
I haven't seen anything like that, sorry. Very few parties outside pact-foundation provide standalone libs that integrate with Pact.

abubics
2021-02-12 07:00
Seems like you might want a helper function, or default structure where you can override specific fields (maybe a builder pattern?) to help reduce your copypasta

r.strauch
2021-02-12 10:15
has joined #pact-jvm

tusharvarm
2021-02-12 11:46
yeah that's true

tusharvarm
2021-02-12 11:47
Common question is how to create a LambdaDSLJSONBody object for the large request?

tusharvarm
2021-02-12 11:47
and all the fields are mandatory

ztlboy05
2021-02-12 14:57
has joined #pact-jvm

smith260194
2021-02-12 15:22
has joined #pact-jvm

smith260194
2021-02-12 15:29
Hi everyone :wave:, I am having trouble in setting default request headers for every pact using junit 5, is this possible?

smith260194
2021-02-12 16:06
This is for the consumer side, I see a way in the docs provider side but not for consumer side. But I do see a way to do it for junit4 :thinking_face:

dabfleming
2021-02-12 20:34
has joined #pact-jvm

prasanthp
2021-02-13 00:45
has joined #pact-jvm

uglyog
2021-02-13 00:48
It has only been implemented for JUnit 4

smith260194
2021-02-13 05:13
Thank you!

uglyog
2021-02-13 05:53
Raise an issue at the Github project to get it implemented for JUnit 5

jokubas.lekevicius
2021-02-13 17:45
There's this line in the https://docs.pact.io/faq/#can-i-generate-my-pact-file-from-something-like-swagger > Something that could be useful, however, is to generate skeleton Pact test code from a Swagger document. If you're interested in working on this, have a chat to the maintainers on the Pact Slack. Not sure if someone made any progress on this, but it sounds exactly like what you'd want

tjones
2021-02-14 15:00
I don?t have the code, but @abubics and I have written groovy tests for Scala code using pact-jvm. It?s definitely possible.

abubics
2021-02-14 22:20
@tusharvarm What language are you using? With Kotlin, I could structure the Java 8 DSL a lot better to make it readable. Still, the 25-30 field have to be specified somewhere...

bhardwajdiwakar
2021-02-14 22:38
has joined #pact-jvm

jun.li
2021-02-15 01:23
```Request to provider method failed with an exception: Failed to invoke provider method 'aConditionUserMitigatedEvent' (java.lang.RuntimeException)``` Hi, when I have a test has an null pointer exception I get message like this only showing me java.lang.RuntimeException, are there any way to show me full error trace like junit?

uglyog
2021-02-15 01:41
Set the JVM system property `pact.showStacktrace` to `true`

jun.li
2021-02-15 01:41
thanks

abubics
2021-02-15 03:01
Oh something I also missed, the question of whether the fields are relevant is different to whether they're mandatory. > Are all of those fields significant for every interaction? Like, you might have an item count, or status, or something, that's pertinent to some interactions and not especially relevant in others.

hiteshpatadia
2021-02-15 06:29
has joined #pact-jvm

laxmi.somni508
2021-02-15 10:28
Thanks, if you have any sample on Github/stackoverflow/medium etc.. then kindly share the link. It will be a big help . Thanks :+1:

vikrant.sarkaniya
2021-02-15 13:31
has joined #pact-jvm

lemitrou
2021-02-15 14:20
has joined #pact-jvm

bhardwajdiwakar
2021-02-15 14:30
Hi guys, I am still learning pact and wanted to go through it slowly. I?ve already gone through tutorials but all of them directly jumps to using pact-broker. Our endgoal is to use pact-broker and pactflow but, in order to convince our organization's larger team, we are planning to use it internally between 2 of our services. For starters we are planning to share pact json manually. I am not able to find a relevant tutorial for using a pact file in provider side and failing tests/build without using pact-broker or aws s3. Kindly provide relevant links/tutorials for this. P.S. I am able to use pact-broker but want to use physical json file. Kindly provide relevant links

phil.endsley
2021-02-15 14:45
On the provider, instead of using the `@PactBroker` annotation, you can use `@PactFolder`. Everything else is the same. There are a few other methods you can use too (ex: supplying a url), but the folder is probably easiest for a poc. https://docs.pact.io/implementation_guides/jvm/provider/junit/#pact-folder

bhardwajdiwakar
2021-02-15 16:24
Thanks @phil.endsley, Can this be achieved as a maven/gradle verification stage as well?

laxmi.somni508
2021-02-15 16:54
Thanks @tjones, if you have any sample on Github/stackoverflow/medium etc.. then kindly share the link. It will be a big help . Cheers..

abubics
2021-02-15 22:54
There are definitely options (https://docs.pact.io/implementation_guides/jvm/provider/gradle/#2-define-the-pacts-between-your-consumers-and-providers) for the gradle provider plugin, not sure about maven


tjones
2021-02-16 04:35
Sorry, I don?t have the code. Have a look for resources on calling scala from groovy (or whatever JVM language you prefer to write your tests in).

abubics
2021-02-16 05:03
I feel like we might've only done a Groovy test consumer, and then the Scala bits were using the itv plugin :thinking_face: it was, like, 4 years ago, though.

tjones
2021-02-16 06:46
I thought we didn?t use the itv plugin

tjones
2021-02-16 06:47
I remember it was spiked, but we needed something it didn?t support, so we did the consumer tests in groovy calling down to the client

abubics
2021-02-16 07:17
hm . . . I guess I could check . . . :upside_down_face:

helloraj
2021-02-16 08:09
has joined #pact-jvm

uladzislau_danilchyk
2021-02-16 09:42
Hi everyone! I have experienced with the following behavior when some of the tests failed but in reports/logs I can't see details (body diff, etc) what actually wrong. But some time ago it was working fine. But additionally I would like to add that I need to run debug panel with variables to see what was actually wrong. Could you investigate it?

wesleythomaswilliams
2021-02-16 11:12
25-30 fields seems pretty manageable, I've recently finished working on a contract that was about 600 fields (this was a MessagePact) and it wasn't built with LambdaDSLJSONBody, we're using PactDslJsonBody.

wesleythomaswilliams
2021-02-16 11:13
And yes, I'd have given my right arm for a tool that would have auto-generated that, but thankfully there was some repetition in the contract that allowed some level of copy/paste.

jamesmlucas
2021-02-16 19:29
has joined #pact-jvm

jamesmlucas
2021-02-16 19:57
Hi folks, I am trying to get a Pact consumer test running for first time and running into issue where the test fails with the following (details posted in thread reply)

jamesmlucas
2021-02-16 19:59
: ```org.apache.http.NoHttpResponseException: 127.0.0.1:1234 failed to respond``` I have this dependency in my build.gradle: ``` testImplementation "au.com.dius:pact-jvm-consumer-junit5:4.0.10"``` The test is modeled after the examples and is as follows (some code removed for brevity): ```@ExtendWith(PactConsumerTestExt.class) @PactTestFor(providerName = "si-service-platformconfiguration", port = "1234") public class AlternateIDServicePact { private Map<String, String> headers = MapUtils.putAll(new HashMap<>(), new String[] { "Content-Type", "application/json" }); @BeforeEach public void setUp(MockServer mockServer) { assertThat(mockServer, is(notNullValue())); } @Pact(consumer = "consumer") public RequestResponsePact sequence(PactDslWithProvider builder) { return builder .given("sequence request") .uponReceiving("a request for a sequence with orgs, type of PMConfig and desired quantity") .path("/hello") .method("GET") .willRespondWith() .headers(headers) .status(200) .body(new PactDslJsonBody() .stringType("prefix") .integerType("start") .integerType("end") ) .toPact(); } @Test @PactTestFor(pactMethod = "sequence") void test(MockServer mockServer) throws IOException { HttpResponse httpResponse = Request.Get(mockServer.getUrl() + "/hello") .execute() .returnResponse(); Assertions.assertEquals(httpResponse.getStatusLine().getStatusCode(), 200); } }``` Debug logging shows that request is being received and matching is being executed, but the http client seems to close prematurely: ```2021-02-16T13:51:02,284 DEBUG [HTTP-Dispatcher] a.c.d.p.c.BaseJdkMockServer: Received request: method: GET path: /hello query: {} headers: {Accept-encoding=[gzip,deflate], Accept=[application/json; charset=UTF-8], Connection=[Keep-Alive], Host=[127.0.0.1:1234], User-agent=[Apache-HttpClient/4.5.13 (Java/11.0.10)]} matchers: MatchingRules(rules={}) generators: Generators(categories={}) body: EMPTY 2021-02-16T13:51:02,284 DEBUG [HTTP-Dispatcher] a.c.d.p.c.m.RequestMatching$Companion: comparing to expected request: method: GET path: /hello query: {} headers: {} matchers: MatchingRules(rules={path=Category(name=path, matchingRules={})}) generators: Generators(categories={}) body: MISSING 2021-02-16T13:51:02,285 DEBUG [HTTP-Dispatcher] a.c.d.p.c.m.Matching: Found a matcher for text/plain -> au.com.dius.pact.core.matchers.PlainTextBodyMatcher@4756c6de 2021-02-16T13:51:02,285 DEBUG [HTTP-Dispatcher] a.c.d.p.c.m.RequestMatching$Companion: Request mismatch: [] 2021-02-16T13:51:02,286 DEBUG [Test worker] o.a.h.i.c.Wire: http-outgoing-2 << "end of stream" 2021-02-16T13:51:02,287 DEBUG [Test worker] o.a.h.i.c.LoggingManagedHttpClientConnection: http-outgoing-2: Close connection 2021-02-16T13:51:02,287 DEBUG [Test worker] o.a.h.i.c.LoggingManagedHttpClientConnection: http-outgoing-2: Shutdown connection 2021-02-16T13:51:02,287 DEBUG [Test worker] o.a.h.i.e.ConnectionHolder: Connection discarded 2021-02-16T13:51:02,288 DEBUG [Test worker] o.a.h.i.c.PoolingHttpClientConnectionManager: Connection released: [id: 1][route: {}->http://127.0.0.1:1234][total available: 0; route allocated: 0 of 100; total allocated: 0 of 200] 2021-02-16T13:51:02,288 INFO [Test worker] o.a.h.i.e.RetryExec: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://127.0.0.1:1234: The target server failed to respond```

jamesmlucas
2021-02-16 20:01
I'm not able to debug the issue. It seems like the mock server is working correctly but possibly closing the connection prematurely?

gabe707
2021-02-16 20:31
has joined #pact-jvm

wangpei9679
2021-02-16 21:29
has joined #pact-jvm

matt.fellows
2021-02-16 22:59
hmmm strange

matt.fellows
2021-02-16 22:59
This does ring a bell, have you searched the Pact JVM issues?

geir
2021-02-16 23:03
has joined #pact-jvm

jamesmlucas
2021-02-16 23:12
Thanks for the response. Yes, have looked pretty thoroughly at existing issues. I got called onto something else, but I notice if I comment out the body in the mock, the test will pass, so I think it's something w/ the way I'm building the response body....

matt.fellows
2021-02-16 23:13
To my eyes, it looks completely sensible!

uglyog
2021-02-17 00:09
Can you try with the latest 4.1 version?

jamesmlucas
2021-02-17 04:11
Hi -- I haven't tried to use latest version -- I don't currently see anything later than 4.0.10 in maven. For the time being, it looks like casting the body to string is fixing issue: ``` .body(new PactDslJsonBody() .stringType("prefix") .integerType("start") .integerType("end") .toString() )```

uglyog
2021-02-17 04:22
But you loose the matchers that way ```implementation 'au.com.dius.pact.consumer:junit5:4.1.17'```

jamesmlucas
2021-02-17 05:24
:facepalm: Thank you. In the process of upgrading, I believe I found the core issue. Upgrading commons-lang3 to 3.11 (from 3.0) in my project appears to have fixed the issue in 4.0.10 as well. Thanks again for the assistance!

uglyog
2021-02-17 05:36
Ok, there is an issue for this. Could you add a comment on how it fixed it for you? https://github.com/pact-foundation/pact-jvm/issues/1054 and https://github.com/pact-foundation/pact-jvm/issues/1176

soruma.net
2021-02-17 05:58
has joined #pact-jvm

jamesmlucas
2021-02-17 07:06
Sure thing, done. Let me know if I can add any additional info.

uladzislau_danilchyk
2021-02-17 10:59
Hi everyone! How to tag provider after publishing verification results (junit5)? I thought about `pactbroker.providerTags` but maybe it is not..

uladzislau_danilchyk
2021-02-17 11:24
Found `pact.provider.tag`

uladzislau_danilchyk
2021-02-17 11:45
Does pact-jvm have possibility to publish only positive results to pact broker? In our project we want to store in Pact broker only positive results due to having many pushes to pact broker.

matt.fellows
2021-02-17 11:58
> In our project we want to store in Pact broker only positive results due to having many pushes to pact broker. why is too many pushes a problem?

matt.fellows
2021-02-17 11:58
Not publishing verification results is like not reporting failed unit test runs

matt.fellows
2021-02-17 11:58
(in Pact land)

therimpact
2021-02-17 12:30
has joined #pact-jvm

amaljayaraj07
2021-02-17 17:51
has joined #pact-jvm

jokubas.lekevicius
2021-02-17 20:31
600!!!!! How many layers did this message have? Wow

andrzej.igielski
2021-02-17 21:41
has joined #pact-jvm

uglyog
2021-02-17 21:53
No, it stores all the results it gets

uglyog
2021-02-17 21:54
Thank you!

wesleythomaswilliams
2021-02-17 22:00
It wasn't as deep as it was broad, but it did require @uglyog putting in a change to Pact to handle it. :smile:

mikewagner21
2021-02-18 03:15
has joined #pact-jvm

wilkinsweiqiangliang
2021-02-18 04:42
Hey @matt.fellows @uglyog im getting `http://au.com.dius.pact.provider.junitsupport.loader.NoPactsFoundException: No Pact files were found to verify` with my ci/cd pipeline now, anything changed on pact end?

wilkinsweiqiangliang
2021-02-18 04:43
``` [TestEventLogger] com.lendi.decisions.actions.condition.pact.ConditionWorkerPactTest > com.lendi.decisions.actions.condition.pact.ConditionWorkerPactTest > initializationError FAILED 2021-02-18T15:36:16.689+1100 [DEBUG] [TestEventLogger] au.com.dius.pact.provider.junitsupport.loader.NoPactsFoundException: No Pact files were found to verify 2021-02-18T15:36:16.689+1100 [DEBUG] [TestEventLogger] Provider: xxx 2021-02-18T15:36:16.689+1100 [DEBUG] [TestEventLogger] Source: xxx https://xxx.pactflow.io: consumerVersionSelectors=[ConsumerVersionSelector(tag=test123, latest=true, consumer=, fallbackTag=master), ConsumerVersionSelector(tag=development, latest=true, consumer=, fallbackTag=), ConsumerVersionSelector(tag=staging, latest=true, consumer=, fallbackTag=), ConsumerVersionSelector(tag=production, latest=true, consumer=, fallbackTag=)] 2021-02-18T15:36:16.689+1100 [DEBUG] [TestEventLogger] at au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider.provideTestTemplateInvocationContexts(PactJUnit5VerificationProvider.kt:43) 2021-02-18T15:36:16.689+1100 [DEBUG] [TestEventLogger] at org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor.lambda$execute$0(TestTemplateTestDescriptor.java:102) 2021-02-18T15:36:16.689+1100 [DEBUG] [TestEventLogger] at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:271) 2021-02-18T15:36:16.689+1100 [DEBUG] [TestEventLogger] at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654)```

uglyog
2021-02-18 04:52
Not that I know of

wilkinsweiqiangliang
2021-02-18 04:53
any suggestion? the contract is on pactflow, running successfully for a few days

uglyog
2021-02-18 05:02
I need to ask @bethskurrie

wilkinsweiqiangliang
2021-02-18 05:02
cool thanks

uglyog
2021-02-18 05:25
Just checking, what version of Pact-JVM are you using?

wilkinsweiqiangliang
2021-02-18 05:26
`pactVersion = '4.1.11'`

uglyog
2021-02-18 05:27
Can you try 4.1.17?

wilkinsweiqiangliang
2021-02-18 05:27
sure

uglyog
2021-02-18 05:27
Actually, you mentioned it was working before

uglyog
2021-02-18 05:28
Must be something in the Pactflow backend

wilkinsweiqiangliang
2021-02-18 05:28
yea it working like today before lunch time

wilkinsweiqiangliang
2021-02-18 05:28
still the contract is in pactflow

bethskurrie
2021-02-18 05:38
I'm looking into it @wilkinsweiqiangliang

wilkinsweiqiangliang
2021-02-18 05:38
Thank you

wilkinsweiqiangliang
2021-02-18 05:54
seems upgrade to `4.2` fix the issue

wilkinsweiqiangliang
2021-02-18 05:54
still checking

bethskurrie
2021-02-18 05:57
I haven't been able to reproduce it yet @wilkinsweiqiangliang

bethskurrie
2021-02-18 05:57
keep me updated as you find out more.

wilkinsweiqiangliang
2021-02-18 05:57
cool

bethskurrie
2021-02-18 06:17
@wilkinsweiqiangliang I'm still working on identifying the cause. It's something to do with the fallback tag.

wilkinsweiqiangliang
2021-02-18 06:17
yea

bethskurrie
2021-02-18 06:17
Can you add a separate selector for the master pacts?

wilkinsweiqiangliang
2021-02-18 06:17
okay

bethskurrie
2021-02-18 06:18
Just a plain one, no fallback. That should get you going for now, until I can identify the fix required.

wilkinsweiqiangliang
2021-02-18 06:18
thanks

wilkinsweiqiangliang
2021-02-18 06:18
i believe this is causing the issue

bethskurrie
2021-02-18 07:20
@wilkinsweiqiangliang We've resolved the issue.

bethskurrie
2021-02-18 07:20
Please try running your verifications again.

wilkinsweiqiangliang
2021-02-18 07:33
any suggestion on changes? do i need an version upgrade?

wilkinsweiqiangliang
2021-02-18 07:33
i found a stackoverflow like this issue


matt.fellows
2021-02-18 07:33
nothing to do on your end - you should be able to continue as is

uglyog
2021-02-18 07:34
But the fallback tag was fixed in a later version, so upgrade to 4.1.17 at least

wilkinsweiqiangliang
2021-02-18 07:34
sure

matt.fellows
2021-02-18 07:35
So there were two separate issues I think. One was the fallback tag itself not actually working in your version of Pact JVM

matt.fellows
2021-02-18 07:35
the second was that no pacts were being returned at all (we?ve fixed that at the Pactflow end)

wilkinsweiqiangliang
2021-02-18 07:35
:+1:

khandelwalbhushan
2021-02-18 08:10
has joined #pact-jvm

aniket.agarwal
2021-02-18 09:21
has joined #pact-jvm

arpit.modani
2021-02-18 09:43
has joined #pact-jvm

byronth
2021-02-18 11:45
has joined #pact-jvm

isa.levine
2021-02-18 23:37
has joined #pact-jvm

isa.levine
2021-02-19 00:02
Hi folks! :wave::slightly_smiling_face: I have a question about defining provider state names inside the `builder.given()` method. I have a situation where my provider state is the same (?default state?), and I have two interactions with that state I want to test (both are GET requests, and the only difference is the value of an integer query param). However, using `.given("default state")` for both interactions? state leads to an error where one of the two requests is not received. I can solve this by simply changing the ?default state? string, but then I may not know if I?m actually testing the same provider state in each interaction. The docs on provider states (https://docs.pact.io/getting_started/provider_states/) seem to suggest I should be able to create multiple interactions under the same state. But I did notice that all the examples show different strings in that `.given()` method. So, I wanted to clarify: ? does the string in ALL `.given()` calls need to be unique to avoid this error? ? is there a way to register multiple interactions under the same state?

uglyog
2021-02-19 00:10
The interaction description + provider states must be unique. You can re-use the provider state, but you need to provide a different interaction description.

uglyog
2021-02-19 00:11
Also, if you are defining both interactions in the same test, then the mock server is going to expect to receive both. Use separate tests for each one.

isa.levine
2021-02-19 00:14
The interaction description is what's inside `uponReceiving`, right? Here's a gist of the code I have, where I'm using the same string in `given` but different ones in `uponReceiving`: https://gist.github.com/isalevine/87ffb2e331ce48f7cc7a232c2c457de1

uglyog
2021-02-19 00:15
You're defining both at the same time, so the test has to make both requests

uglyog
2021-02-19 00:15
Use separate tests for each one

isa.levine
2021-02-19 00:17
Sounds good, thank you! I'll refactor them to be in separate tests. Strange though, I thought I _was_ making both requests by firing them off in the same `@Test` method. Maybe something to do with this CloseableHttpResponse class then? (I'm coming from Ruby, so all this Java HTTP stuff is brand-new to me)

uglyog
2021-02-19 00:20
I'm not sure why one of the requests was not received. You may need to debug your test to see what is happening

uglyog
2021-02-19 00:20
You can also re-use the same httpClient in your test, you don't need a separate one

isa.levine
2021-02-19 00:21
Good to know, I appreciate that!

uglyog
2021-02-19 00:22
Actually, now that I look at your example, the regex in the second request will match the first one, so it is probably matching both requests

isa.levine
2021-02-19 00:22
OHHHH that's a great point, thanks for catching that! I'll play around with that first

isa.levine
2021-02-19 00:49
Yep, better regex fixed the problem. Thank you so much for catching that (and for generally doing a sanity check for me)! :slightly_smiling_face:

brian.pfretzschner
2021-02-19 10:15
has joined #pact-jvm

philipchardwick
2021-02-19 16:21
I'm looking at creating a test in the junit provider for the issue I created above, I need to have a pact source produce a pending pact for my test. What's the best way to go about this? It'd be nice to do a more wholistic test for pending pacts in the junit library - like some of the other tests written in java. One idea would be to create a custom pact source like a `MockPactBrokerSource` which `implements PactLoader` and which returns a `BrokerUrlSource` from `getPactSource()`

uglyog
2021-02-20 01:34
The mock source would work

chitra.adikesavan
2021-02-20 15:50
has joined #pact-jvm

tausif2909
2021-02-22 06:10
HI, I have 3 consumer services `consumer-1`, `consumer-2` & `consumer-3` and 1 provider verification service `provider-1` I have written the code for all 3 consumer services and those are published to pact server. and also written provider verification for `consumer-1`, verification for consumer 2 & 3 is pending. Provider verification for `consumer-1` is working fine. But it also starts verification for `consumer-2` & `consumer-3` in jenkinks pipeline even though I have not written any code of it and ending up with build failure of provider service How do I skip the verification for `consumer-2` and `consumer-3` till the time I write verification code for it?

uglyog
2021-02-22 06:12
The verification is run for all published pacts. You only need one test for it, not one for each consumer

tausif2909
2021-02-22 06:17
But all 3 consumers are from different services. is there any way we can temporarily skip or disable verification for specific in interaction or all calls in a consumer?

ankita.soni
2021-02-22 07:26
has joined #pact-jvm

jacek.helper
2021-02-22 08:03
has joined #pact-jvm

matt.fellows
2021-02-22 09:12
a few options

matt.fellows
2021-02-22 09:13
1. Use pending pacts (this won?t fail your build, because they are new expectations) 2. Use tags to manage workflows. If a Pact has been merged into, say, `master` but the provider can?t verify it, now the consumer can?t deploy

matt.fellows
2021-02-22 09:14
see the CI/CD workshop in howtolearn for more on these workflows

2021-02-22 09:14
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

tausif2909
2021-02-22 09:29
Thanks @matt.fellows

seanw122
2021-02-22 15:36
has joined #pact-jvm

akennedy
2021-02-22 15:54
has joined #pact-jvm

esimpson
2021-02-22 16:42
has joined #pact-jvm

dagrawal
2021-02-22 17:24
has joined #pact-jvm

venkata.pro
2021-02-22 21:47
has joined #pact-jvm

siddharth.gupta
2021-02-23 12:23
has joined #pact-jvm

siddharth.gupta
2021-02-23 12:24
can someone point me to any example code to run provider PactVerification tests using junit5


wesleythomaswilliams
2021-02-23 12:36
Feel free to fire questions at me, I might be able to answer, we use Junit5/Maven/Spring. Also see Matt's link in the post below yours

siddharth.gupta
2021-02-23 12:37
Thanks

laxmi.somni508
2021-02-23 14:51
Hello Helpful Guys, We're trying to implement PACT framework in our organisation. I've had a interesting query from a Android developer - " If from Android Consumer side, we're creating few PACT files & ultimately would be sending it over towards BE Provider, once set-up is complete. So, if we have HTTP header in response coming from Backend API. So tomorrow, in the header file if Backend starts to send few more fields, then should PACT test-framework (mainly consumer-side) catch it?" Do we need to go in such level of details in PACT testing? Kindly provide some light. Thanks

brendan.donegan
2021-02-23 14:56
@laxmi.somni508 it shouldn?t be possible for *extra* response headers to break anything, AFAIK

phil.endsley
2021-02-23 14:58
Pact would "catch" it by receiving all headers the provider sends, but as long as the provider response still contains everything the consumer defines, verification should still pass.

laxmi.somni508
2021-02-23 14:58
Noted.:+1: Thanks a lot for quickly clarifying @brandonbeard86 @phil.endsley

jordan.levin
2021-02-23 19:13
has joined #pact-jvm

francesco.latorre
2021-02-24 05:59
has joined #pact-jvm

francislainy.campos
2021-02-24 08:34
These two articles I?ve written with some samples may help you.



aniket.g2185
2021-02-24 09:13
has joined #pact-jvm

sundaresank360
2021-02-24 12:12
has joined #pact-jvm

uladzislau_danilchyk
2021-02-24 13:13
@uglyog, do you plan to implement such functionality to define which type of results need to be stored: all, positive, negative? I think it would be useful. Especially for our project at least.

francislainy.campos
2021-02-24 13:39
Hi, is it possible not to have a port appended to the provider url like this https://api.br.internal:8443/v1/states that comes from ```@BeforeEach void before(PactVerificationContext context) { context.setTarget(new HttpsTestTarget("api.br.internal")); }```

ryanlevell
2021-02-24 13:56
I am using -Dpactbroker.consumerversionselectors.tags to run the provider side tests against specific tags. I also want to include the latest contract regardless of the tag. Is there a way to get the latest contract that has no tag yet via the system property?

ryanlevell
2021-02-24 14:37
I believe an empty comma separated value is working e.g. ?,prod? will grab 2 contracts; latest any tag, and latest prod tag

jhawthor
2021-02-24 15:18
has joined #pact-jvm

ryanlevell
2021-02-24 15:52
Never mind, that did not work. The /for-provider endpoint supports no tag, but not sure if it is possible via this system property.

chris.r.thomas
2021-02-24 16:54
has joined #pact-jvm

peter.cook
2021-02-24 17:05
has joined #pact-jvm

jayeshguru81
2021-02-24 18:34
has joined #pact-jvm

ben.kirberger
2021-02-24 19:16
has joined #pact-jvm

uglyog
2021-02-24 22:11
No, there is no plan for that. Previously, it only pushed up the failed results, but was fixed recently to store all results because that was causing problems.

bethskurrie
2021-02-24 22:24
@uladzislau_danilchyk what problems are you noticing with the number of pushes?

bethskurrie
2021-02-24 22:39
You can set the consumer name in the consumer version selectors.


abubics
2021-02-25 00:27
Omitting the port would just imply the default port for that protocol (i.e. 443 for `https`, 80 for `http`, etc) . . . is that your intent?


rejeesh.g
2021-02-25 04:31
Is there any solution to the this issue https://github.com/pact-foundation/pact-jvm/issues/319

rejeesh.g
2021-02-25 04:32
Say my request is as per this sample request "Certification": { "Java": { "Version": "1.5", "Year": "2015" }, "Scala": { "Version": "1.6", "Year": "2016" }, "C#": { "Version": "1.7", "Year": "2017" }, "C": { "Version": "1.8", "Year": "2018" } }

rejeesh.g
2021-02-25 04:33
and i want to test the interaction as per the below request "Certification": { "Java": { "Version": "1.5", "Year": "2015" }, "Scala": null, "C#": null, "C": null, }

rejeesh.g
2021-02-25 04:36
How do we specify the body = new PactDslJsonBody() to expect a nullvalue json object or have value

phil.endsley
2021-02-25 04:39
I don't think Pact currently supports optional values in contracts. https://docs.pact.io/faq/#why-is-there-no-support-for-specifying-optional-attributes The most common advice is to define multiple interactions where the optional field is the expected value, and one where it is null

rejeesh.g
2021-02-25 04:41
ok Thanks

m.stephkan
2021-02-25 05:30
has joined #pact-jvm

matt.fellows
2021-02-25 07:49
It doesn't support optionals

matt.fellows
2021-02-25 07:49
Correct

matt.fellows
2021-02-25 07:50
We are trialling a provider driven approach in Pactflow where a consumer uploads a pact with their examples, and provider verifies their OAS and we check compatability

matt.fellows
2021-02-25 07:50
This would allow optionals as the OAS schema allows it

matt.fellows
2021-02-25 07:50
DM me if keen to hear more

francislainy.campos
2021-02-25 08:21
Hi, not really. I don?t want the port to appear at all on the url.

stephen.tjasink
2021-02-25 08:23
has joined #pact-jvm

uladzislau_danilchyk
2021-02-25 10:04
@bethskurrie, i'm working on a huge project with large team > 150 members. And we have too much pushes into pact broker. We don't know restrictions of pact broker storage and it would be good to have a possibility to choose what types of verification results it can store

beatrizwaclawek
2021-02-25 20:27
has joined #pact-jvm

zhoutianli1234
2021-02-25 21:09
has joined #pact-jvm

abubics
2021-02-26 00:16
Sorry, I'm not suggesting that you replace it with an explicit `:80` or `:443`, but that would be the effective outcome.

travis.day
2021-02-26 04:06
has joined #pact-jvm

andrew.cunningham
2021-02-26 11:13
has joined #pact-jvm

andrew.cunningham
2021-02-26 11:18
Hey :wave: Has anyone seen `No signature of method: http://au.com.dius.pact.core.pactbroker.PactBrokerClient.uploadPactFile()` while using `au.com.dius:pact-jvm-consumer-junit_2.12:3.6.15`?

uglyog
2021-02-27 00:49
Make sure you are not mixing major versions of the Pact JVM libraries. That version is pretty old.

brianmasschaele
2021-02-27 13:27
has joined #pact-jvm

pedroefajardo_pactio
2021-02-27 17:18
has joined #pact-jvm

bethskurrie
2021-02-28 22:54
@uladzislau_danilchyk that number of pushes should be fine. but what you want to do is configure the clean up task https://github.com/pact-foundation/pact_broker/issues/360#issuecomment-735216009

bethskurrie
2021-02-28 22:54
And make sure you've provisioned it well enough!

bethskurrie
2021-02-28 22:55
> And we have too much pushes into pact broker. Again, what problems are you noticing? Are the responses slow? Is anything timing out?

r.strauch
2021-02-28 23:59
Hey, In order to test a HTTP 500 response from my Spring Boot application, I've setup the following state with Mockito using `@SpyBean` on the `mailService`. When debugging, I can see that the service is proxied by Mockito but the exception is not thrown. Am I missing something? The `mailService` is actually a service which is injected in another service. Maybe that causes the problem? ```@State("SERVER_ERROR") public void serverError() { doThrow(new IOException()) .when(mailService) .sendMessage(any(User.class), anyBoolean(), any(MailType.class), anyMap(), anyMap()); }```

dominic_herrmann
2021-03-01 06:54
has joined #pact-jvm

uladzislau_danilchyk
2021-03-01 09:47
@bethskurrie, Responses growing up

laxmi.somni508
2021-03-01 15:19
Hi @abubics, Hope you're doing great. Just wanted to check if you managed to find more info about this? Thanks [P.S::round_pushpin: If I send you a message outside your usual working hours, please do not feel that you need to respond immediately.]

andrew.cunningham
2021-03-01 15:55
Does Pact work with Kotlin DSL in Gradle?

thanuxxxx
2021-03-01 16:23
Hey guys, I have a `Springboot` microservice where I run my pact provider tests along with other integration tests by executing `mvn verify` command. I am planning to have separate Jenkins pipeline for pact since regular build takes a bit longer to complete. My question is how can I just run pact tests only via maven commands. mvn verify also executes all of other time consuming integration tests, I don't want to execute other tests. Do we have a way to do that?

andrew.cunningham
2021-03-01 16:55
Turns out it does not play nice...

wesleythomaswilliams
2021-03-01 17:14
Hi Shan, we also have springboot microservices. Our pact tests run as part of our unit test stage in our pipeline using `mvn test`, but I've created maven profiles so I can execute test types separately. So I could run `mvn test -Pcontract-tests` if I wanted and that would only run tests that fit a naming convention (e.g. *ContractTest)

thanuxxxx
2021-03-01 17:35
Okay

wesleythomaswilliams
2021-03-01 18:26
Was that helpful? Happy to try and provide more details.

thanuxxxx
2021-03-01 21:57
Yes, that was helpful. I'll be keep posting if I encounter any road blocks

abubics
2021-03-02 00:04
yarr, I found a lot of things didn't play too nice with the Kotlin DSL last time I tried (about 15 months ago) . . .

abubics
2021-03-02 02:10
Just had a quick look through backups, we created a test consumer using itv.scalapact, and JVM gradle provider, with the older-style "provide a state-change endpoint" setup.

ryanlevell
2021-03-02 02:47
@uglyog do the `pactbroker.consumerversionselectors.*` properties support no tag e.g. just the latest contract, in addition to other tags? Something like: `-Dpactbroker.consumerversionselectors.tags=<no tag>,prod` It appears that the API can support no tag: `localhost:9292/pacts/provider/{provider}/for-verification` ```{ "consumerVersionSelectors": [ { "latest": true } ] }```

andrew.cunningham
2021-03-02 09:04
It would be a nice addition to the product - most new projects I work on use the Gradle Kotlin DSL

matthew.long
2021-03-02 14:08
has joined #pact-jvm

gayatree.eee
2021-03-02 14:31
Hi, Can you please point me to the system property which can be used for --tag in create-version-tag

ryanlevell
2021-03-02 15:46
For consumer tag(s): -Dpact.consumer.tags For provider tag: -Dpact.provider.tag Sorry on mobile or would link the source.

gayatree.eee
2021-03-02 15:48
-Dpact-provider-tag works for tagging publishing contract verification result. It is not working for create-version-tag, which is used to tag in postdeploy stage.

ryanlevell
2021-03-02 15:50
You mean via the Pact Broker CLI or by maven plugin?

tmoncm
2021-03-02 17:17
has joined #pact-jvm

phoenixcampos01
2021-03-02 21:25
has joined #pact-jvm

gayatree.eee
2021-03-03 03:27
Pact Broker CLI

uglyog
2021-03-03 04:13
It wasn't designed that way, if it does, it is a side-effect

uglyog
2021-03-03 04:13
Pact Broker CLI is not built with Java, so does not use system properties


ryanlevell
2021-03-03 04:23
Any suggestions to allow for it? I have it working in a branch with an empty comma and without breaking the other logic. But it looks kind of funny and could cause issues for anyone currently expecting ?empty == do not include?: `-Dpactbroker.consumerversionselectors.tags=,prod`

uglyog
2021-03-03 04:28
Can you raise a Githuib issue for this so I can look at what you're trying to do when I have a chance

abubics
2021-03-03 04:31
tangential, but I haven't tried the Kotlin DSL for gradle many times . . . I love Kotlin, but the groovy DSL still works better for me

gayatree.eee
2021-03-03 06:19
ok.. is there any other way to achieve the same without using Pact Broker CLI..

andrew.cunningham
2021-03-03 09:26
I was wondering if anyone has tried to tie the creation of their pacts to UI/automation testing? I have an Android project where SETs have created tests for all requests/responses - I want to utilise this pre-existing set up to generate my Pacts. Any thoughts?


matt.fellows
2021-03-03 09:42
Can be done. The precondition that must hold for it to work with current Pact 1. Pacts must be reliably generated i.e. the consumer side must actually do what the test data does. If it drifts you have no confidence 2. Need to be careful with data. This is likely to cause pain for the provider team This being said, we're exploring a way to do that better at Pactflow.

francislainy.campos
2021-03-03 09:53
Yes, the port comes up when I don?t add it there, so I was looking for a way not to have this appended to the url. But it?s not a biggie, I can workaround it if there?s no such a way. Thanks.

hugh.paul.mcgowan
2021-03-03 17:52
has joined #pact-jvm

uglyog
2021-03-03 21:36
What's wrong with using the Pact Broker CLI? Why does it have to be a system property?

normanrs
2021-03-04 11:18
has joined #pact-jvm

jayson.bailey
2021-03-04 19:18
has joined #pact-jvm

matias.waterloo
2021-03-05 13:34
Hi, is it possible to mix HttpTestTarget and MessageTestTarget in a single test class (junit5)? What is the approach to have both http and async provider tests (but single serivce/provider) fetched from the broker?

josue.boix
2021-03-05 13:43
QQ. So I have a pact with Upon receiving: ```{ "method": "GET", "path": "/api/v1/url/csv" }``` And the response that look as follows: ```{ "status": 200, "body": "NAME,EMAIL\nSome name, \nOther name, \n" }``` Which is actually a *csv* response. I create a provider verification test, everything works as expected but fails with the following message: ```BodyTypeMismatch: Expected a response type of 'application/json' but the actual type was 'text/plain'``` Why is it expecting a `application/json` body?

ryanlevell
2021-03-05 15:27
~Your confusing your ?body? field with the real ?response body?. Your response body IS json. Your json has 2 fields, status and body. Your ?body? is not the same as the ?response body?. The ?response body? is JSON. The ?body? field is in CSV format, but that is within the overall JSON payload. When you created the pact, you probably used a `PactDslJsonBody` object. Pact uses this to determine the content-type (I think). The only time the content-type should be ?text/*? is when the whole payload is literally plain text. I haven?t done it, but I imagine you can override the response content-type in the pact. Although ?application/json? is not required, is the correct content-type for this response.~

ryanlevell
2021-03-05 15:29
Your confusing your ?body? field with the real ?response body?. Your response body IS json. Your json has 2 fields, status and body. Your ?body? is not the same as the ?response body?. The ?response body? is JSON. The ?body? field is in CSV format, but that is within the overall JSON payload. When you created the pact, you probably used a `PactDslJsonBody` object. Pact uses this to determine the content-type (I think). The only time the content-type should be ?text/*? is when the whole payload is literally plain text. I haven?t done it, but I imagine you can override the response content-type in the pact. Although ?application/json? is not required, is the correct content-type for this response.

ryanlevell
2021-03-05 17:14
I have a similar question from consumer side. Can the same consumer/provider pair be used in a contract that requires both sync/async interactions? Or does that require 2 separate contracts with slightly different names? Consumer -> SameProviderApi Consumer -> SameProviderQueue

josue.boix
2021-03-05 17:30
Thanks for the reply. The pact was actually created from the FE using JS, with the following: ```describe('Description', () => { beforeAll(async () => { await provider.setup() await provider.addInteraction({ uponReceiving: 'Some request', state: 'Some state', withRequest: { method: 'GET', headers: { Accept: 'text/csv', }, path: url, }, willRespondWith: { status: 200, body: EXPECTED_CSV_RESPONSE, }, }) }, SETUP_TIMEOUT)```

olarrmide
2021-03-05 19:29
has joined #pact-jvm

matt.fellows
2021-03-05 22:03
You haven't specified the content type on the response

matt.fellows
2021-03-05 22:03
I think without it, it will default to looking for JSON

uglyog
2021-03-06 00:21
The new V4 Pact format supports both message and http interactions in the same file, but it is largely untested. I'll try setup an example test that does that.

josue.boix
2021-03-08 09:28
If I do as follows: Upon receiving: ```{ "method": "GET", "path": "/api/v1/url/csv" "headers": { "Accept": "text/csv" }``` And the response that look as follows: ```{ "status": 200, "headers": { "Content-Type": "text/csv" } "body": "NAME,EMAIL\nSome name, \nOther name, \n" }``` I get the following error instead: ```java.lang.AssertionError: Failures: 1) Get headquarter drafts list 1.1) com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 5 path $ at au.com.dius.pact.provider.spring.target.MockMvcTarget.testInteraction(MockMvcTarget.kt:86) at au.com.dius.pact.provider.junit.InteractionRunner$interactionBlock$statement$1.evaluate(InteractionRunner.kt:226) at au.com.dius.pact.provider.junit.RunStateChanges.evaluate(RunStateChanges.kt:30) at au.com.dius.pact.provider.junit.InteractionRunner.run(InteractionRunner.kt:162) at au.com.dius.pact.provider.junit.PactRunner.runChild(PactRunner.kt:150) at au.com.dius.pact.provider.junit.PactRunner.runChild(PactRunner.kt:56) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)```

matt.fellows
2021-03-08 09:38
hmmm could you please share the generated pact file and the provider test?

josue.boix
2021-03-08 09:58
The problem is see here is that the controller is not sending any response header, and that causes problems with pact

josue.boix
2021-03-08 09:58
```MockHttpServletResponse: Status = 200 Error message = null Headers = [Content-Disposition:"attachment; filename=file-2-2021-03-08T10:57:22.256.csv"] Content type = null Body = DMT,NAME...```

josue.boix
2021-03-08 09:58
And then the error ```java.lang.AssertionError: Failures: 1) Get headquarter drafts list 1.1) com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 5 path $ at au.com.dius.pact.provider.spring.target.MockMvcTarget.testInteraction(MockMvcTarget.kt:86) at au.com.dius.pact.provider.junit.InteractionRunner$interactionBlock$statement$1.evaluate(InteractionRunner.kt:226) at au.com.dius.pact.provider.junit.RunStateChanges.evaluate(RunStateChanges.kt:30) at au.com.dius.pact.provider.junit.InteractionRunner.run(InteractionRunner.kt:162) at au.com.dius.pact.provider.junit.PactRunner.runChild(PactRunner.kt:150) at au.com.dius.pact.provider.junit.PactRunner.runChild(PactRunner.kt:56) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)```

laxmi.somni508
2021-03-08 12:35
Hello Helpful Pact-JVM community-members, Brining your attention to below Question on Stackoverflow. We're looking for a simple barebone sample boilerplate of Pact-JVM usage on Scala codebase. If you're aware of any sample on public Github / blog etc.. then kindly share the link in answer. _This could you useful to not only to myself but other newbies in the future_:pray: [p.s. - There's a 50 Stackoverflow points bounty for a successful answer..:tada:] Thanks a lot https://stackoverflow.com/q/66426214/2451016

philipchardwick
2021-03-08 15:25
Hey, does v4.2.x support both V3 and V4 of the pact specification? Are there any considerations to take when upgrading?

uglyog
2021-03-08 22:05
The V4 work is still in progress and not not complete. But it does support all specification formats.

uglyog
2021-03-08 22:05
There has been some refactoring and removal of some deprecated methods, but nobody has reported any issues when upgrading as yet

mjsmcp
2021-03-08 23:46
has joined #pact-jvm